:root {
  --bg: #eef0ed;
  --surface: #fcfcf8;
  --surface-2: #e6ece8;
  --ink: #171a18;
  --muted: #6d716c;
  --line: #d5ddd3;
  --teal: #0d766f;
  --teal-2: #cfe8e3;
  --coral: #ba5644;
  --gold: #aa7419;
  --green: #527b46;
  --violet: #665d9f;
  --shadow: 0 20px 54px rgba(23, 31, 28, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.atlas-app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 310px) minmax(300px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(252, 252, 248, 0.94);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #99c8c1;
  border-radius: 8px;
  background: var(--teal-2);
  color: #064c47;
  font-weight: 850;
}

.brand h1,
.map-head h2,
.lens-head h2 {
  margin: 0;
  line-height: 1.1;
}

.brand h1 {
  font-size: 19px;
}

.brand p,
.eyebrow,
.microcopy {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.command {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  min-width: 0;
  overflow: hidden;
}

.command input {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  padding: 0 14px;
}

.command button,
.mode-button,
.mobile-mode,
.quiet-button,
.icon-button,
.pill-button,
.paper-link,
.tool-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  min-height: 34px;
  padding: 0 11px;
  font-weight: 760;
}

.command button {
  height: 42px;
  border-width: 0 0 0 1px;
  border-radius: 0;
  color: var(--teal);
}

.mode-nav {
  display: flex;
  gap: 8px;
}

.mode-button.active,
.mobile-mode.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  min-height: 0;
}

.map-panel {
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-content: start;
  min-width: 0;
  min-height: 0;
  padding: 22px;
  gap: 14px;
}

.map-head,
.lens-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.map-head h2,
.lens-head h2 {
  font-size: 28px;
}

.atlas-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quiet-button {
  background: rgba(255, 255, 255, 0.75);
}

.quiet-button.strong,
.tool-button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.quiet-button.warn {
  border-color: #d2aa68;
  background: #fff5dc;
  color: #694300;
}

.atlas-stage {
  position: relative;
  isolation: isolate;
  height: min(58vh, 560px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(25, 34, 30, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(25, 34, 30, 0.045) 1px, transparent 1px),
    linear-gradient(135deg, rgba(13, 118, 111, 0.08), transparent 42%),
    linear-gradient(315deg, rgba(186, 86, 68, 0.07), transparent 38%),
    #f8faf5;
  background-size: 34px 34px, 34px 34px, 100% 100%, 100% 100%, auto;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.atlas-stage::after {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), transparent 24%),
    linear-gradient(0deg, rgba(19, 25, 22, 0.045), transparent 26%);
}

.atlas-chart,
#atlasSvg {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 420px;
  display: block;
}

.atlas-chart[hidden],
#atlasSvg[hidden] {
  display: none;
}

.atlas-edge {
  stroke: rgba(82, 85, 79, 0.24);
  stroke-linecap: round;
}

.atlas-node {
  cursor: pointer;
}

.atlas-node circle {
  fill: #f8fbf8;
  stroke: var(--teal);
  stroke-width: 0.45;
  filter: drop-shadow(0 4px 8px rgba(20, 40, 36, 0.14));
  transition: transform 160ms ease, fill 160ms ease, stroke 160ms ease;
}

.atlas-node:hover circle,
.atlas-node.active circle {
  fill: var(--teal-2);
  stroke: #074f49;
}

.atlas-node text {
  pointer-events: none;
  fill: #15201d;
  font-size: 2.7px;
  font-weight: 800;
  text-anchor: middle;
}

.atlas-node .node-count {
  fill: var(--muted);
  font-size: 2.2px;
  font-weight: 680;
}

.heat-ring {
  fill: none;
  stroke: var(--coral);
  stroke-width: 0.7;
  opacity: 0.68;
}

.route-band,
.timeline-band {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.86);
  padding: 12px;
}

.band-title {
  margin-bottom: 9px;
  color: #343a36;
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.route-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 8px;
}

.route-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  padding: 9px;
  min-height: 72px;
  text-align: left;
}

.route-item strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.route-item span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.timeline {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(34px, 1fr);
  gap: 5px;
  align-items: end;
  min-height: 86px;
}

.month-cell {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 6px;
  min-width: 0;
}

.month-bar {
  align-self: end;
  border-radius: 5px 5px 2px 2px;
  background: var(--teal);
  min-height: 5px;
}

.month-label {
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  white-space: nowrap;
}

.lens-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.lens-head {
  padding: 19px 18px;
  border-bottom: 1px solid var(--line);
}

.lens-head h2 {
  font-size: 23px;
}

.icon-button {
  width: 34px;
  padding: 0;
  font-size: 20px;
}

.lens-body {
  min-height: 0;
  overflow: auto;
  padding: 0 18px 24px;
}

.section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.section:last-child {
  border-bottom: 0;
}

.section h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.statement {
  margin: 0;
  color: #25302c;
  font-size: 15px;
  line-height: 1.62;
}

.question {
  margin: 10px 0 0;
  color: var(--coral);
  font-size: 14px;
  line-height: 1.5;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #fbfaf6;
}

.stat strong {
  display: block;
  font-size: 20px;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
}

.chip-row,
.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-button {
  min-height: 31px;
  font-size: 12px;
}

.pill-button.active {
  border-color: var(--teal);
  background: var(--teal-2);
  color: #064f49;
}

.paper-list {
  display: grid;
  gap: 0;
}

.paper-item {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 12px 0;
  color: inherit;
  text-align: left;
}

.paper-item:hover {
  color: var(--teal);
}

.paper-title {
  font-size: 14px;
  font-weight: 780;
  line-height: 1.35;
}

.paper-meta,
.mini-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.mini-badge {
  border-radius: 4px;
  background: #efeee7;
  color: #4b514c;
  padding: 3px 6px;
}

.agent-activity {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
  padding: 12px;
}

.activity-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 7px rgba(13, 118, 111, 0.12);
}

.agent-activity.running .activity-dot {
  animation: activityPulse 1.5s ease-in-out infinite;
}

.agent-activity.done .activity-dot {
  background: var(--green);
  box-shadow: 0 0 0 7px rgba(82, 127, 70, 0.12);
}

.agent-activity.error .activity-dot {
  background: var(--coral);
  box-shadow: 0 0 0 7px rgba(186, 86, 68, 0.12);
}

.activity-copy {
  min-width: 0;
}

.activity-title {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  color: var(--muted);
  font-size: 12px;
}

.activity-title strong {
  color: #17201d;
  font-size: 14px;
}

.activity-detail {
  margin-top: 3px;
  color: #4c5550;
  font-size: 13px;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.activity-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  white-space: nowrap;
}

@keyframes activityPulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 7px rgba(13, 118, 111, 0.1);
  }

  50% {
    transform: scale(0.82);
    box-shadow: 0 0 0 10px rgba(13, 118, 111, 0.18);
  }
}

.search-brief h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.compact-section {
  display: grid;
  gap: 8px;
}

.mini-chart-row,
.search-topic-row {
  margin-top: 10px;
}

.month-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 0 6px 6px 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #ffffff;
  padding: 0 7px;
  color: #4c5550;
  font-size: 11px;
  font-weight: 720;
}

.followup-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.followup-row input {
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  padding: 0 10px;
  outline: 0;
}

.dialogue-list {
  display: grid;
  gap: 8px;
}

.dialogue-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.dialogue-row.user {
  background: #f4f8f6;
}

.dialogue-row strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
}

.dialogue-row div {
  white-space: pre-wrap;
  color: #27312d;
  font-size: 13px;
  line-height: 1.58;
}

.ai-box,
.reader-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
  padding: 14px;
  line-height: 1.62;
}

.ai-output,
.abstract-text,
.markdown-preview {
  white-space: pre-wrap;
  line-height: 1.62;
  font-size: 14px;
}

.reader-title {
  margin: 0 0 8px;
  font-size: 19px;
  line-height: 1.25;
}

.paper-link {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  min-height: 32px;
  font-size: 12px;
}

.tool-button {
  min-height: 34px;
  font-size: 12px;
}

.empty-state {
  padding: 18px 0;
  color: var(--muted);
  line-height: 1.5;
}

.mobile-nav {
  display: none;
}

@media (min-width: 1181px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .atlas-app {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  .workspace {
    min-height: 0;
    overflow: hidden;
  }

  .map-panel,
  .lens-panel {
    height: 100%;
    min-height: 0;
  }

  .map-panel {
    overflow: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
  }

  .lens-panel {
    overflow: hidden;
  }

  .lens-body {
    overflow: auto;
  }

  .reader-mode .workspace {
    grid-template-columns: minmax(430px, 0.78fr) minmax(660px, 1.22fr);
  }

  .reader-mode .map-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .reader-mode .map-head h2 {
    font-size: 24px;
  }

  .reader-mode .atlas-actions {
    justify-content: flex-start;
  }

  .reader-mode .route-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reader-mode .lens-head {
    padding: 22px 30px;
  }

  .reader-mode .lens-body {
    padding: 0 30px 38px;
  }

  .reader-mode .lens-body .section {
    max-width: 900px;
    margin: 0 auto;
  }

  .reader-mode .lens-head h2 {
    font-size: 26px;
  }

  .reader-mode .reader-title {
    font-size: 24px;
    line-height: 1.22;
  }

  .reader-mode .reader-box,
  .reader-mode .ai-box {
    padding: 18px;
  }

  .reader-mode .markdown-preview,
  .reader-mode .ai-output,
  .reader-mode .abstract-text {
    font-size: 15px;
  }
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .mode-nav {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .lens-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .lens-body {
    max-height: none;
  }

  .route-list {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }
}

@media (max-width: 760px) {
  html,
  body,
  .atlas-app,
  .workspace,
  .map-panel,
  .lens-panel {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .atlas-app {
    padding-bottom: 56px;
  }

  .topbar {
    position: static;
    gap: 12px;
    padding: 14px;
  }

  .brand h1 {
    font-size: 17px;
  }

  .mode-nav {
    display: none;
  }

  .workspace {
    display: block;
  }

  .map-panel {
    display: block;
    padding: 14px;
  }

  .map-head {
    align-items: flex-start;
  }

  .map-head h2 {
    font-size: 23px;
  }

  .atlas-actions {
    justify-content: flex-end;
  }

  .quiet-button {
    min-height: 32px;
    padding: 0 9px;
    font-size: 12px;
  }

  .atlas-stage {
    height: 360px;
    margin-top: 14px;
    min-height: 360px;
    width: 100%;
    max-width: calc(100vw - 28px);
  }

  .atlas-chart,
  #atlasSvg {
    min-height: 360px;
    width: 100%;
    max-width: 100%;
  }

  .agent-activity {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .activity-meta {
    grid-column: 2;
  }

  .route-band,
  .timeline-band {
    margin-top: 12px;
    max-width: calc(100vw - 28px);
    overflow-x: hidden;
  }

  .route-list {
    grid-template-columns: 1fr;
  }

  .timeline {
    overflow-x: auto;
    grid-auto-columns: 42px;
  }

  .lens-head {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 5;
  }

  .lens-head h2 {
    font-size: 20px;
  }

  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px;
    border-top: 1px solid var(--line);
    background: rgba(255, 254, 250, 0.96);
    z-index: 30;
  }

  .mobile-mode {
    min-height: 39px;
  }
}
