:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22252f;
  --border: #2a2d3a;
  --text: #e1e4ed;
  --text-muted: #8b8fa3;
  --accent: #6c8cff;
  --accent-hover: #8ba3ff;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  --orange: #fb923c;
  --radius: 8px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", "SF Mono", monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Navigation */
nav.top-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

nav.top-nav .nav-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 2rem;
  height: 56px;
}

nav.top-nav .nav-links-wrap {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

nav.top-nav .nav-links-wrap::-webkit-scrollbar { display: none; }

nav.top-nav .logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

nav.top-nav .nav-links {
  display: flex;
  gap: 0.25rem;
  white-space: nowrap;
}

nav.top-nav .nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  transition: all 0.15s;
}

nav.top-nav .nav-links a:hover,
nav.top-nav .nav-links a.active {
  color: var(--text);
  background: var(--surface-hover);
}

/* Page header */
h1.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 1.5rem;
}

h1.page-title span.count {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 1rem;
  margin-left: 0.5rem;
}

.page-header-row {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.filter-link {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.filter-link:hover {
  color: var(--accent);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  transition: border-color 0.15s;
}

a.card {
  text-decoration: none;
  color: inherit;
  display: block;
}

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

.card .card-title {
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
}

.card:hover .card-title {
  color: var(--accent);
}

.edge-relation-inline {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
}

.read-set-nodes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.read-set-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  text-decoration: none;
  transition: border-color 0.15s;
}

.read-set-chip:hover {
  border-color: var(--accent);
}

.read-set-chip-name {
  font-size: 0.8125rem;
  color: var(--text);
  font-weight: 500;
}

.read-set-chip:hover .read-set-chip-name {
  color: var(--accent);
}

.read-set-chip-tools {
  font-size: 0.625rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.read-set-edges {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.read-set-edge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.read-set-edge-relation {
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.card .card-meta {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 0.35rem;
}

.card .card-desc {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  line-height: 1.5;
}

/* Kind sections */
.kind-section {
  margin-bottom: 2rem;
}

.kind-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.kind-header .kind-count {
  font-weight: 400;
  margin-left: 0.5rem;
}

/* Badge */
.badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-kind {
  background: rgba(108, 140, 255, 0.15);
  color: var(--accent);
}

/* Kind-specific badge colors */
.badge-kind-person       { background: rgba(74, 222, 128, 0.15);  color: #4ade80; }
.badge-kind-company      { background: rgba(251, 146, 60, 0.15);  color: #fb923c; }
.badge-kind-project      { background: rgba(96, 165, 250, 0.15);  color: #60a5fa; }
.badge-kind-tool         { background: rgba(34, 211, 238, 0.15);  color: #22d3ee; }
.badge-kind-content      { background: rgba(192, 132, 252, 0.15); color: #c084fc; }
.badge-kind-event        { background: rgba(251, 191, 36, 0.15);  color: #fbbf24; }
.badge-kind-talk         { background: rgba(232, 170, 36, 0.15);  color: #e8aa24; }
.badge-kind-concept      { background: rgba(167, 139, 250, 0.15); color: #a78bfa; }
.badge-kind-discussion   { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
.badge-kind-decision     { background: rgba(52, 211, 153, 0.15);  color: #34d399; }
.badge-kind-idea         { background: rgba(253, 224, 71, 0.15);  color: #fde047; }
.badge-kind-risk         { background: rgba(248, 113, 113, 0.15); color: #f87171; }
.badge-kind-action_item  { background: rgba(251, 146, 60, 0.15);  color: #fb923c; }
.badge-kind-question     { background: rgba(56, 189, 248, 0.15);  color: #38bdf8; }
.badge-kind-opportunity  { background: rgba(74, 222, 128, 0.15);  color: #4ade80; }
.badge-kind-offer        { background: rgba(96, 165, 250, 0.15);  color: #60a5fa; }
.badge-kind-agreement    { background: rgba(45, 212, 191, 0.15);  color: #2dd4bf; }
.badge-kind-market_signal { background: rgba(244, 114, 182, 0.15); color: #f472b6; }


.badge-completed { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.badge-extracted { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.badge-reextracted { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.badge-processing { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.badge-failed { background: rgba(248, 113, 113, 0.15); color: var(--red); }
.badge-pending { background: rgba(139, 143, 163, 0.15); color: var(--text-muted); }
.badge-queued { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.badge-requeued { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.badge-extracting { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.badge-started { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.badge-re-extraction-failed { background: rgba(251, 146, 60, 0.15); color: var(--orange); }
.badge-create { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.badge-update { background: rgba(251, 146, 60, 0.15); color: var(--orange); }

/* Extraction rows (details/summary) */
.extraction-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s;
}

.extraction-row:hover {
  border-color: rgba(108, 140, 255, 0.3);
}

.extraction-row > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9375rem;
}

.extraction-row > summary::-webkit-details-marker { display: none; }

.extraction-row > summary::before {
  content: "▸";
  color: var(--text-muted);
  font-size: 0.7rem;
  width: 0.8rem;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.extraction-row[open] > summary::before {
  transform: rotate(90deg);
}

.extraction-row .row-title {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.extraction-row .row-title:hover {
  color: var(--accent);
}

.extraction-row .row-title a {
  color: inherit;
  text-decoration: none;
}

.extraction-row .row-title a:hover {
  color: var(--accent);
}

/* Diff section */
.diff-section {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: grid;
  gap: 0.4rem;
  font-size: 0.8125rem;
}

.diff-section.diff-empty {
  color: var(--text-muted);
  font-style: italic;
}

.diff-entry {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr auto 1fr;
  gap: 0.6rem;
  align-items: baseline;
  font-family: var(--mono);
}

.diff-field {
  color: var(--text-muted);
  font-weight: 500;
}

.diff-before {
  color: var(--red);
  text-decoration: line-through;
  text-decoration-color: rgba(248, 113, 113, 0.4);
  word-break: break-word;
}

.diff-after {
  color: var(--green);
  word-break: break-word;
}

.diff-arrow {
  color: var(--text-muted);
}

/* Node detail */
.node-header {
  margin-bottom: 2rem;
}

.node-header .back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8125rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.node-header .back-link:hover { color: var(--accent); }

.node-kind {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.node-connections {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.node-description {
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.7;
  max-width: 640px;
}

/* Attributes */
.attrs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.attr-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.attr-card .attr-key {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.attr-card .attr-value {
  font-size: 0.9375rem;
  font-weight: 500;
  overflow-wrap: break-word;
  word-break: break-all;
}

.attr-breakdown {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.1rem 0.75rem;
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.attr-breakdown dt {
  font-weight: 400;
}

.attr-breakdown dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tokens-cell {
  font-variant-numeric: tabular-nums;
}

.tokens-total {
  font-weight: 500;
}

.tokens-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Edges section */
.edges-section {
  margin-top: 2rem;
}

.edges-section h2 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.75rem;
}

.edges-section h3.read-set-anchor {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin: 1.25rem 0 0.5rem;
}

.edges-section h3.read-set-anchor code {
  font-family: var(--mono);
  font-size: 0.8125rem;
  background: var(--surface-hover);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.edges-section h3.read-set-anchor code a {
  color: var(--accent);
  text-decoration: none;
}

.edges-section h3.read-set-anchor code a:hover {
  text-decoration: underline;
}

.edge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.5rem;
  transition: border-color 0.15s;
}

.edge-card:hover {
  border-color: rgba(108, 140, 255, 0.3);
}

.edge-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  font-size: 0.9375rem;
}

.edge-context {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 0.5rem;
  line-height: 1.5;
  text-align: center;
}

.edge-attrs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
  justify-content: center;
}

.edge-attr {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(139, 143, 163, 0.1);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius);
}

.edge-attr-key {
  color: var(--text);
  font-weight: 500;
}

.edge-source {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  justify-content: flex-start;
}

.edge-target {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  justify-content: flex-end;
}

.edge-source .badge,
.edge-target .badge {
  font-size: 0.6rem;
  padding: 0.1rem 0.4rem;
  flex-shrink: 0;
}

.edge-node-name {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.edge-node-name:hover { color: var(--accent); }

.edge-node-current {
  color: var(--text-muted);
}

.edge-arrow {
  display: flex;
  align-items: center;
  padding: 0 0.25rem;
}

.edge-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.edge-line-arrow {
  flex: 1;
  height: 1px;
  background: var(--border);
  position: relative;
  margin-right: 6px;
}

.edge-line-arrow::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 4px solid transparent;
  border-left: 6px solid var(--text-muted);
}

.edge-relation {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(108, 140, 255, 0.12);
  border: 1px solid rgba(108, 140, 255, 0.25);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  flex-shrink: 0;
  white-space: nowrap;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:hover { background: var(--surface-hover); }
tr.clickable-row { cursor: pointer; }

code {
  font-family: var(--mono);
  font-size: 0.8125rem;
  background: var(--surface);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: var(--accent);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 1rem;
  margin-top: 0.5rem;
}

/* Graph layout */
.graph-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 2rem;
}

.sidebar {
  position: sticky;
  top: 72px;
  align-self: start;
}

.kind-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kind-nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  transition: all 0.15s;
}

.kind-nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.kind-nav-item.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
}

.kind-nav-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  .graph-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
  }
  .kind-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.25rem;
  }
}

/* Search */
.search-form {
  margin-bottom: 1.5rem;
}
.search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.125rem;
  font-family: var(--font);
  outline: none;
}
.search-input:focus {
  border-color: var(--accent);
}
.search-input::placeholder {
  color: var(--text-muted);
}

/* Provenance */
.node-provenance {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.provenance-heading {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.provenance-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.provenance-item {
  display: flex;
  gap: 0.75rem;
  font-size: 0.8125rem;
}

.provenance-item dt {
  color: var(--text-muted);
  min-width: 7rem;
  flex-shrink: 0;
}

.provenance-item dd {
  margin: 0;
  color: var(--text);
}

.provenance-date {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-left: 0.25rem;
}

.text-muted { color: var(--text-muted); }

/* Links */
a { color: var(--accent); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--accent-hover); }

/* Flash messages */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.flash-notice {
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.3);
  color: var(--green);
}
.flash-alert {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--red);
}

/* Reextract form */
.reextract-form {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.model-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.75rem;
  font-family: var(--mono);
  padding: 0.35rem 0.4rem;
  height: 1.75rem;
}
.btn-sm {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  height: 1.75rem;
}
.btn-sm:hover {
  background: var(--accent-hover);
}

.btn-sm:disabled,
.btn-sm[disabled] {
  background: var(--surface-hover);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

.model-select:disabled,
.model-select[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.content-search-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.search-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.content-block mark {
  background: rgba(251, 191, 36, 0.2);
  color: var(--text);
  border-radius: 2px;
  padding: 0.05rem 0;
}

.content-block mark.mark-active {
  background: rgba(251, 191, 36, 0.5);
  outline: 1px solid var(--yellow);
}

.content-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.7;
  color: var(--text);
  max-height: 600px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Mobile */
@media (max-width: 640px) {
  .container {
    padding: 1rem 0.85rem;
  }

  nav.top-nav {
    padding: 0 0.85rem;
  }

  nav.top-nav .nav-inner {
    gap: 0.75rem;
  }

  nav.top-nav .nav-links a {
    padding: 0.4rem 0.5rem;
  }

  h1.page-title {
    font-size: 1.4rem;
  }

  .page-header-row {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Tables — horizontal scroll wrapper via wrapping element or overflow */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  thead th, tbody td {
    padding: 0.6rem 0.75rem;
  }

  /* Edge row: stack source / relation / target vertically */
  .edge-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    justify-items: start;
  }

  .edge-source, .edge-target {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .edge-arrow {
    padding: 0.15rem 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
  }

  /* Vertical arrow between source and target when stacking on mobile */
  .edge-arrow::before {
    content: "↓";
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1;
  }

  .edge-line, .edge-line-arrow {
    display: none;
  }

  .edge-context, .edge-attrs {
    text-align: left;
    justify-content: flex-start;
  }

  /* Diff entry: stack field / before / arrow / after vertically */
  .diff-entry {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .diff-arrow {
    display: none;
  }

  /* Provenance: tighten dt min-width */
  .provenance-item {
    flex-direction: column;
    gap: 0.15rem;
  }

  .provenance-item dt {
    min-width: 0;
    font-size: 0.75rem;
  }

  /* Cards: reduce padding */
  .card {
    padding: 1rem;
  }

  /* Extraction row summary — allow wrapping */
  .extraction-row > summary {
    flex-wrap: wrap;
  }

  /* Reextract form inline on mobile */
  .reextract-form {
    flex-wrap: wrap;
  }
}
