:root {
  --bg: #e8eaed;
  --surface: #f4f5f7;
  --surface-elevated: #fafbfc;
  --border: #d8dce2;
  --text: #2c3340;
  --text-muted: #6b7585;
  --accent: #5a7a8f;
  --accent-dark: #3d5a73;
  --green: #6b8f7a;
  --green-btn: #7a9488;
  --blue-egg: #3d4f66;
  --shadow: 0 4px 24px rgba(44, 51, 64, 0.08);
  --shadow-lg: 0 12px 40px rgba(44, 51, 64, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
}

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

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.brand-icon {
  width: 36px;
  height: 28px;
}

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.search-wrap {
  flex: 1;
  max-width: 320px;
  margin: 0 auto;
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 0.55rem 1rem 0.55rem 2.25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
  color: var(--text);
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(90, 122, 143, 0.15);
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.topnav {
  display: flex;
  gap: 1.5rem;
  flex-shrink: 0;
}

.topnav a {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid transparent;
}

.topnav a:hover {
  color: var(--text);
}

.topnav a.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--text);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.avatar-btn {
  border: none;
  padding: 0;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  line-height: 0;
}

.avatar-btn:hover .avatar {
  border-color: var(--accent);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.dropdown-wrap {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.dropdown-menu[hidden] {
  display: none;
}

.dropdown-menu button,
.dropdown-menu a {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  cursor: pointer;
}

.dropdown-menu button:hover,
.dropdown-menu a:hover {
  background: var(--surface);
}

.search-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  padding: 0.25rem;
}

.search-suggestions[hidden] {
  display: none;
}

.suggestion-item {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text);
}

.suggestion-item span {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.suggestion-item:hover {
  background: var(--surface);
}

/* Layout */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
  padding: 1.25rem 0.75rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.6);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

.stats-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-elevated);
}

.stat-chip {
  border: none;
  background: none;
  font: inherit;
  font-size: inherit;
  color: inherit;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
  cursor: pointer;
}

.stat-chip:hover {
  background: var(--surface);
  color: var(--text);
}

.stats-bar strong {
  color: var(--text);
  font-weight: 600;
}

.main-viewport {
  flex: 1;
  min-height: 0;
  position: relative;
}

.route-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.route-panel[hidden] {
  display: none;
}

.inner-panel {
  padding: 1.5rem 2rem;
  overflow-y: auto;
  height: 100%;
}

.inner-panel h2 {
  margin: 0 0 0.5rem;
}

.field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0.75rem 0 0.35rem;
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  max-width: 360px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface-elevated);
}

.field-textarea {
  resize: vertical;
}

.tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.tag-btn {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.tag-btn:hover {
  border-color: var(--accent);
}

.workflow-log,
.intel-feed {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  white-space: pre-wrap;
}

.report-list,
.venture-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.report-list button,
.venture-list button {
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border: none;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
  margin-bottom: 0.4rem;
}

.report-list button:hover,
.venture-list button:hover,
.venture-list button.highlight {
  border-color: var(--accent);
  background: #fff;
}

.api-key-row {
  display: flex;
  gap: 0.5rem;
  max-width: 400px;
}

.api-key-row .field-input {
  flex: 1;
}

.btn-ghost {
  margin-top: 0.5rem;
  width: 100%;
  padding: 0.45rem;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
}

.btn-ghost:hover {
  color: var(--text);
}

.stats-bar .sep {
  opacity: 0.4;
}

.map-stage {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 480px;
  overflow: hidden;
  background: linear-gradient(160deg, #eef0f3 0%, #e4e7eb 50%, #eceef1 100%);
  transition: box-shadow 0.4s ease;
}

.map-stage.pulse {
  box-shadow: inset 0 0 60px rgba(90, 122, 143, 0.25);
}

.map-nests {
  position: absolute;
  inset: 0;
}

.connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.conn {
  fill: none;
  stroke: #c5ccd6;
  stroke-width: 1.2;
  opacity: 0.55;
}

/* Nests + magnifier */
.nest {
  --push-x: 0px;
  --push-y: 0px;
  --mag-scale: 1;
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(calc(-50% + var(--push-x)), calc(-50% + var(--push-y))) scale(var(--mag-scale));
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  border: 1.5px solid rgba(200, 208, 218, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 12px rgba(255, 255, 255, 0.5), var(--shadow);
  transition: transform 0.12s ease-out, box-shadow 0.2s ease;
  pointer-events: none;
  z-index: 1;
}

.nest.highlight {
  border-color: var(--accent);
  box-shadow: inset 0 2px 12px rgba(255, 255, 255, 0.5), 0 0 0 3px rgba(90, 122, 143, 0.2);
}

.nest-label {
  position: absolute;
  top: -1.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: 0.02em;
  pointer-events: none;
  user-select: none;
}

.eggs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
  max-width: 90px;
  padding: 0.5rem;
  pointer-events: auto;
}

.egg-btn {
  --push-x: 0px;
  --push-y: 0px;
  --mag-scale: 1;
  width: 22px;
  height: 28px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  border: none;
  padding: 0;
  position: relative;
  cursor: pointer;
  transform: translate(var(--push-x), var(--push-y)) scale(var(--mag-scale));
  transition: transform 0.1s ease-out, box-shadow 0.15s ease, opacity 0.2s;
  box-shadow:
    inset -2px -4px 8px rgba(0, 0, 0, 0.08),
    inset 2px 2px 6px rgba(255, 255, 255, 0.7),
    0 2px 6px rgba(44, 51, 64, 0.12);
  flex-shrink: 0;
  z-index: 2;
}

.egg-btn.dimmed {
  opacity: 0.35;
}

.egg-btn.selected {
  box-shadow:
    inset -2px -4px 8px rgba(0, 0, 0, 0.08),
    inset 2px 2px 6px rgba(255, 255, 255, 0.7),
    0 0 0 3px rgba(90, 122, 143, 0.45),
    0 4px 14px rgba(90, 122, 143, 0.35);
}

.egg-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.egg-btn.egg-white {
  background: linear-gradient(145deg, #fff 0%, #e8ecf0 100%);
}

.egg-btn.egg-blue {
  background: linear-gradient(145deg, #5a6d85 0%, var(--blue-egg) 100%);
}

.egg-btn.egg-green {
  background: linear-gradient(145deg, #8faa9a 0%, var(--green) 100%);
}

.egg-btn.egg-blue .egg-logo,
.egg-btn.egg-green .egg-logo {
  color: #eef2f6;
}

.egg-logo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.45rem;
  font-weight: 700;
  color: var(--accent-dark);
  letter-spacing: -0.05em;
}

/* Egg detail panel */
.egg-panel {
  position: absolute;
  width: min(300px, calc(100% - 16px));
  padding: 1.1rem 1.2rem 1rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 30;
  animation: fadeIn 0.2s ease;
  pointer-events: auto;
}

.egg-panel[hidden] {
  display: none;
}

.egg-panel-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--surface);
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

.egg-panel-close:hover {
  color: var(--text);
  background: var(--border);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tooltip-head {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.tooltip-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #dce4ec, #b8c9dc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--accent-dark);
  flex-shrink: 0;
}

.tooltip h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.tooltip-meta {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tooltip-tagline {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
}

.tooltip-desc {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.tooltip-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.btn-outline {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--surface);
}

.btn-primary {
  background: var(--green-btn);
  color: #fff;
  border-color: var(--green-btn);
}

.btn-primary:hover {
  background: var(--green);
}

/* Framework sidebar */
.framework {
  width: 260px;
  flex-shrink: 0;
  padding: 1.5rem 1.25rem;
  background: var(--surface-elevated);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.framework h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.framework-lead {
  margin: 0 0 1.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.framework-diagram {
  position: relative;
  height: 200px;
}

.framework-diagram svg {
  width: 100%;
  height: 100%;
}

.tri-line {
  stroke: #c5ccd6;
  stroke-width: 1;
}

.fw-node {
  position: absolute;
  text-align: center;
  max-width: 110px;
  border: none;
  background: none;
  padding: 0.25rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.fw-node:hover {
  background: rgba(255, 255, 255, 0.7);
}

.fw-node:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fw-node strong {
  display: block;
  font-size: 0.72rem;
  margin-bottom: 0.2rem;
}

.fw-node span:last-child {
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.fw-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-bottom: 0.35rem;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
}

.fw-icon svg {
  width: 16px;
  height: 16px;
}

.fw-top {
  left: 50%;
  top: 0;
  transform: translateX(-50%);
}

.fw-left {
  left: 0;
  bottom: 0;
}

.fw-right {
  right: 0;
  bottom: 0;
}

/* Responsive */
@media (max-width: 1100px) {
  .framework {
    display: none;
  }
}

@media (max-width: 900px) {
  .topnav {
    display: none;
  }

  .sidebar {
    width: 64px;
    padding: 1rem 0.5rem;
  }

  .nav-item span,
  .nav-item {
    font-size: 0;
    justify-content: center;
    padding: 0.65rem;
  }

  .nav-item svg {
    margin: 0;
  }
}

@media (max-width: 600px) {
  .search-wrap {
    display: none;
  }

  .stats-bar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .nest {
    width: 110px;
    height: 110px;
  }

  .egg-btn {
    width: 18px;
    height: 24px;
  }
}

.toast-stack {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.65rem 1rem;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: 280px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}
