:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --panel: #ffffff;
  --ink: #18201d;
  --muted: #66716d;
  --line: #dce2df;
  --accent: #19684c;
  --accent-2: #b6402b;
  --soft: #eef3f0;
  --shadow: 0 1px 2px rgba(18, 32, 27, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: #17211d;
  color: #f5f8f6;
  padding: 24px 18px;
}

.brand {
  font-size: 22px;
  font-weight: 760;
  margin: 0 0 6px;
}

.sidebar p {
  color: #b8c7c0;
  margin: 0 0 24px;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 2px;
}

.nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #7a9188;
  padding: 14px 12px 4px;
  font-weight: 600;
}

.nav a {
  color: #f5f8f6;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
}

.nav a[aria-current="page"],
.nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  text-decoration: none;
}

.main {
  padding: 28px;
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.toolbar.compact {
  align-items: end;
  margin-bottom: 14px;
}

.toolbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

.toolbar h2 {
  margin: 0;
  font-size: 20px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.button,
button {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.button.secondary,
button.secondary {
  color: var(--accent);
  background: #fff;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

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

.card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card {
  padding: 16px;
}

.card h2,
.panel h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.search-field {
  max-width: 360px;
  min-width: min(360px, 100%);
}

label {
  display: grid;
  gap: 6px;
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

textarea {
  min-height: 180px;
  resize: vertical;
}

.status {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
}

.status.error {
  color: var(--accent-2);
}

.graph-layout {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 0;
}

.graph-stage {
  position: relative;
  min-width: 0;
  background: #fbfcfb;
  border-right: 1px solid var(--line);
}

#graph {
  width: 100%;
  height: 100%;
  display: block;
}

.graph-panel {
  background: #fff;
  padding: 20px;
  overflow: auto;
}

.graph-panel h1 {
  font-size: 20px;
  margin: 0 0 8px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--soft);
  color: #33433c;
  padding: 3px 8px;
  font-size: 12px;
}

.node-label {
  pointer-events: none;
  font-size: 12px;
  fill: #1c2521;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
}

.fact-list {
  display: grid;
  gap: 10px;
}

.fact-row {
  border-top: 1px solid var(--line);
  padding: 12px 0 4px;
}

.fact-row:first-child {
  border-top: 0;
}

.fact-title {
  display: inline-block;
  font-weight: 760;
  line-height: 1.3;
}

.fact-row p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.fact-detail {
  width: min(880px, 100%);
}

.fact-detail h1 {
  margin-top: 0;
  font-size: 30px;
  line-height: 1.18;
}

.fact-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  margin: 10px 0 18px;
}

.fact-content {
  font-size: 16px;
}

.fact-content h1,
.fact-content h2,
.fact-content h3 {
  margin-top: 24px;
  line-height: 1.22;
}

.fact-content p {
  margin: 10px 0;
}

.fact-content pre {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f3f1;
  padding: 12px;
}

.fact-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 16px;
  }

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

  .nav a {
    text-align: center;
  }

  .main {
    padding: 18px;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .graph-layout {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .graph-stage {
    height: 62vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

/* Module group cards (homepage) */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.module-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  text-decoration: none;
  color: var(--ink);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.module-card:hover {
  box-shadow: 0 4px 12px rgba(18, 32, 27, 0.1);
  border-color: var(--accent);
  text-decoration: none;
}
.module-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.module-icon {
  font-size: 24px;
  line-height: 1;
}
.module-name {
  font-size: 16px;
  font-weight: 700;
}
.module-desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.module-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.module-link {
  display: inline-block;
  padding: 4px 10px;
  background: var(--soft);
  border-radius: 6px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}
.module-link:hover {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

/* Feature grid (homepage) - kept for backwards compat */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.feature-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.feature-card:hover {
  box-shadow: 0 4px 12px rgba(18, 32, 27, 0.1);
  border-color: var(--accent);
  text-decoration: none;
}
.feature-icon {
  font-size: 28px;
  line-height: 1;
}
.feature-name {
  font-size: 14px;
  font-weight: 600;
}
.feature-desc {
  font-size: 11px;
  color: var(--muted);
}
