/* === Dark theme custom properties (ported from React theme.css) === */
:root {
  --radius: 0.625rem;
  --background: oklch(0.129 0.042 264.695);
  --foreground: oklch(0.984 0.003 247.858);
  --card: oklch(0.14 0.04 259.21);
  --card-foreground: oklch(0.984 0.003 247.858);
  --popover: oklch(0.208 0.042 265.755);
  --popover-foreground: oklch(0.984 0.003 247.858);
  --primary: oklch(0.929 0.013 255.508);
  --primary-foreground: oklch(0.208 0.042 265.755);
  --secondary: oklch(0.279 0.041 260.031);
  --secondary-foreground: oklch(0.984 0.003 247.858);
  --muted: oklch(0.279 0.041 260.031);
  --muted-foreground: oklch(0.704 0.04 256.788);
  --accent: oklch(0.279 0.041 260.031);
  --accent-foreground: oklch(0.984 0.003 247.858);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.551 0.027 264.364);

  /* State colors */
  --state-current: #22c55e;
  --state-stale: #f59e0b;
  --state-missing: #6b7280;
  --state-modified: #3b82f6;
  --state-building: #a855f7;
  --state-failed: #ef4444;
}

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

html {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre { font-family: 'JetBrains Mono', 'Fira Code', monospace; }

/* === Layout === */
.app-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.app-layout .nav { grid-column: 1 / -1; }
.app-layout .sidebar { grid-row: 2; overflow-y: auto; border-right: 1px solid var(--border); padding: 1rem 0; }
.app-layout .main { grid-row: 2; overflow-y: auto; padding: 1.5rem 2rem; }

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
  .app-layout .sidebar { display: none; }
}

/* === Nav === */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.nav-left { display: flex; align-items: center; gap: 0.75rem; }
.nav-right { display: flex; align-items: center; gap: 0.75rem; }

.nav-title {
  font-size: 1rem;
  font-weight: 600;
}

.nav-link {
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--muted-foreground);
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--accent); color: var(--accent-foreground); text-decoration: none; }
.nav-link.active { background: var(--accent); color: var(--accent-foreground); }

.nav-stats { font-size: 0.8rem; color: var(--muted-foreground); }

/* === Logo badge === */
.logo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 700;
  font-size: 0.75rem;
}

/* === Cards === */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.card-header { margin-bottom: 0.75rem; }
.card-title { font-size: 0.875rem; font-weight: 600; }
.card-description { font-size: 0.8rem; color: var(--muted-foreground); margin-top: 0.25rem; }

/* === Stat cards === */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 768px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card { text-align: center; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--muted-foreground); }

/* === Node card grid === */
.node-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 1024px) { .node-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .node-grid { grid-template-columns: 1fr; } }

.node-card {
  display: block;
  transition: background 0.15s;
}
.node-card:hover { background: var(--accent); text-decoration: none; }

.node-card-title { font-size: 0.875rem; font-weight: 500; display: flex; align-items: center; gap: 0.5rem; }
.node-card-path { font-size: 0.75rem; color: var(--muted-foreground); font-family: monospace; margin-top: 0.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-card-meta { font-size: 0.75rem; color: var(--muted-foreground); margin-top: 0.25rem; display: flex; gap: 1rem; }

/* === State dot === */
.state-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.state-dot.current { background: var(--state-current); }
.state-dot.stale { background: var(--state-stale); }
.state-dot.missing { background: var(--state-missing); }
.state-dot.modified { background: var(--state-modified); }
.state-dot.building { background: var(--state-building); }
.state-dot.failed { background: var(--state-failed); }

/* === Badge === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--secondary);
  color: var(--secondary-foreground);
}
.badge.outline { background: transparent; border: 1px solid var(--border); }

/* === Sidebar === */
.sidebar-group { margin-bottom: 0.25rem; }

.sidebar-group summary {
  padding: 0.375rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted-foreground);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-group summary::-webkit-details-marker { display: none; }
.sidebar-group summary::after { content: '\25B6'; font-size: 0.6rem; transition: transform 0.15s; }
.sidebar-group[open] summary::after { transform: rotate(90deg); }

.sidebar-group .badge { margin-left: 0.5rem; font-size: 0.7rem; padding: 0 0.375rem; }

.sidebar-node {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 1rem 0.25rem 1.5rem;
  font-size: 0.8rem;
  color: var(--foreground);
  transition: background 0.1s;
}
.sidebar-node:hover { background: var(--accent); text-decoration: none; }
.sidebar-node.active { background: var(--accent); font-weight: 600; }

/* === Section headings === */
.section-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  margin-top: 1.5rem;
}
.section-heading h3 { font-size: 0.875rem; font-weight: 600; }
.section-heading:first-child { margin-top: 0; }

/* === Detail page === */
.detail-meta { display: grid; grid-template-columns: 100px 1fr; gap: 0.375rem 1rem; font-size: 0.875rem; }
.detail-label { color: var(--muted-foreground); font-weight: 500; }
.detail-value { font-family: monospace; font-size: 0.8rem; word-break: break-all; }

.dep-list { display: flex; flex-wrap: wrap; gap: 0.375rem; }

.dep-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  font-size: 0.75rem;
  color: var(--foreground);
  transition: background 0.1s;
}
.dep-badge:hover { background: var(--accent); text-decoration: none; }

/* === Collapsible prompt === */
.prompt-toggle {
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0;
  list-style: none;
}
.prompt-toggle::-webkit-details-marker { display: none; }
.prompt-toggle::before { content: '\25B6 '; font-size: 0.6rem; }
details[open] .prompt-toggle::before { content: '\25BC '; }

.prompt-content {
  max-height: 500px;
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--background);
  border-radius: var(--radius);
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre-wrap;
  font-family: monospace;
}

/* === Markdown content === */
.md-content { font-size: 0.9rem; line-height: 1.7; }
.md-content h1 { font-size: 1.5rem; font-weight: 700; margin: 1.5rem 0 0.75rem; }
.md-content h2 { font-size: 1.25rem; font-weight: 600; margin: 1.25rem 0 0.5rem; }
.md-content h3 { font-size: 1.1rem; font-weight: 600; margin: 1rem 0 0.5rem; }
.md-content p { margin: 0.5rem 0; }
.md-content ul, .md-content ol { margin: 0.5rem 0; padding-left: 1.5rem; }
.md-content li { margin: 0.25rem 0; }
.md-content code { background: var(--secondary); padding: 0.125rem 0.375rem; border-radius: 0.25rem; font-size: 0.85em; }
.md-content pre { background: var(--secondary); padding: 0.75rem 1rem; border-radius: var(--radius); overflow-x: auto; margin: 0.75rem 0; }
.md-content pre code { background: none; padding: 0; }
.md-content table { border-collapse: collapse; width: 100%; margin: 0.75rem 0; font-size: 0.85rem; }
.md-content th, .md-content td { padding: 0.5rem 0.75rem; border: 1px solid var(--border); text-align: left; }
.md-content th { background: var(--secondary); font-weight: 600; }
.md-content blockquote { border-left: 3px solid var(--border); padding-left: 1rem; color: var(--muted-foreground); margin: 0.75rem 0; }
.md-content a { color: var(--primary); }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* === Graph page === */
.graph-container { width: 100%; overflow: auto; padding: 1rem; }
.graph-container svg { max-width: none; }

/* === Matrix table === */
.matrix-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.matrix-table th, .matrix-table td { padding: 0.5rem 0.75rem; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.matrix-table th { background: var(--secondary); font-weight: 600; white-space: nowrap; }
.matrix-table td a { display: block; margin: 0.125rem 0; }

/* === Search palette === */
.search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}
.search-overlay.open { display: flex; }

.search-dialog {
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 500px;
  max-height: 60vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--foreground);
  font-size: 0.9rem;
  outline: none;
}
.search-input::placeholder { color: var(--muted-foreground); }

.search-results {
  overflow-y: auto;
  max-height: 50vh;
  padding: 0.5rem;
}

.search-group-label {
  padding: 0.375rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted-foreground);
}

.search-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  border-radius: 0.25rem;
  font-size: 0.85rem;
  color: var(--foreground);
  cursor: pointer;
}
.search-item:hover, .search-item.selected { background: var(--accent); text-decoration: none; }

/* === Landing page === */
.landing { min-height: 100vh; display: flex; flex-direction: column; }

.landing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
}

.landing-header-left { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }

.landing-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  max-width: 48rem;
  margin: 0 auto;
}

.landing-hero h1 { font-size: 2.5rem; font-weight: 700; line-height: 1.2; margin-bottom: 1rem; }
.landing-hero h1 span { display: block; color: var(--muted-foreground); font-weight: 400; }
.landing-hero p { color: var(--muted-foreground); max-width: 32rem; margin-bottom: 2rem; }

.landing-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  width: 100%;
  max-width: 36rem;
  margin-bottom: 2rem;
}

.landing-about { text-align: left; width: 100%; max-width: 36rem; }
.landing-about h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.75rem; }
.landing-about p { color: var(--muted-foreground); margin-bottom: 0.75rem; font-size: 0.9rem; }

.landing-footer { text-align: center; padding: 1.5rem; font-size: 0.8rem; color: var(--muted-foreground); }

/* === Auth form === */
.auth-btn {
  padding: 0.375rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--foreground);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}
.auth-btn:hover { background: var(--accent); }

.auth-form {
  display: flex;
  gap: 0.5rem;
}

.auth-input {
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--foreground);
  font-size: 0.875rem;
  outline: none;
  width: 160px;
}
.auth-input:focus { border-color: var(--ring); }
.auth-input.error { border-color: var(--destructive); }

/* === Separator === */
.separator { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* === Utility === */
.text-muted { color: var(--muted-foreground); }
.text-mono { font-family: monospace; font-size: 0.85em; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.hidden { display: none; }
