* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: #1f2937;
  background: #f8fafc;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: #0f172a;
  color: #f1f5f9;
  border-bottom: 1px solid #1e293b;
  flex-wrap: wrap;
}

header .brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: transparent;
  border: none;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  text-align: left;
}

header .brand:hover {
  background: rgba(241, 245, 249, 0.06);
}

header h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#stats {
  font-size: 11px;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}

#view-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: #cbd5e1;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  transition: background 120ms, color 120ms, border-color 120ms;
}

.tab:hover {
  background: rgba(241, 245, 249, 0.06);
  color: #f1f5f9;
}

.tab.active {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #f1f5f9;
  font-weight: 600;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#search {
  background: #1e293b;
  border: 1px solid #334155;
  color: #f1f5f9;
  padding: 5px 28px 5px 10px;
  font-size: 12px;
  border-radius: 5px;
  width: 220px;
  font-family: inherit;
  outline: none;
}

#search::placeholder {
  color: #64748b;
}

#search:focus {
  border-color: #60a5fa;
  background: #0b1220;
}

#search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}

#search-clear:hover { color: #f1f5f9; }

#view-desc {
  padding: 8px 16px;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  font-size: 12px;
  color: #475569;
  font-style: italic;
}

#landing {
  flex: 1;
  overflow-y: auto;
  background:
    linear-gradient(0deg, rgba(15, 23, 42, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.02) 1px, transparent 1px) #f8fafc;
  background-size: 24px 24px;
  padding: 32px 24px 48px;
  display: flex;
  justify-content: center;
}

.landing-inner {
  max-width: 880px;
  width: 100%;
}

.landing-inner h2 {
  font-size: 22px;
  margin: 0 0 10px 0;
  color: #0f172a;
  font-weight: 600;
}

.landing-intro {
  font-size: 14px;
  line-height: 1.5;
  color: #475569;
  margin: 0 0 24px 0;
  max-width: 720px;
}

.landing-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.landing-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px 18px;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  transition: border-color 120ms, transform 120ms, box-shadow 120ms;
}

.landing-tile:hover {
  border-color: #0f172a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -4px rgba(15, 23, 42, 0.12);
}

.tile-title {
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
}

.tile-desc {
  font-size: 12px;
  line-height: 1.45;
  color: #475569;
}

.tile-counts {
  margin-top: 4px;
  font-size: 11px;
  color: #64748b;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", monospace;
}

.landing-foot {
  font-size: 12px;
  color: #94a3b8;
  font-style: italic;
  margin: 0;
}

main {
  display: grid;
  grid-template-columns: 240px 1fr 320px;
  flex: 1;
  min-height: 0;
}

aside {
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
  overflow-y: auto;
  padding: 14px 12px;
  font-size: 12px;
}

aside#detail {
  border-right: none;
  border-left: 1px solid #e2e8f0;
}

#legend section {
  margin-bottom: 18px;
}

#legend h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #475569;
  margin: 0 0 8px 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

#legend h2 .hint {
  font-size: 9px;
  text-transform: none;
  letter-spacing: 0;
  color: #94a3b8;
  font-weight: 400;
  font-style: italic;
}

#legend h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
  margin: 10px 0 4px 0;
  font-weight: 500;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: 3px;
}

.legend-row.toggle {
  background: transparent;
  border: none;
  width: 100%;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  text-align: left;
}

.legend-row.toggle:hover {
  background: #f1f5f9;
}

.legend-row.off {
  opacity: 0.32;
}

.legend-row.empty {
  opacity: 0.35;
}

.legend-row.forced-on .legend-label::after {
  content: ' +';
  color: #16a34a;
  font-weight: 700;
}

.legend-row.forced-off .legend-label::after {
  content: ' −';
  color: #dc2626;
  font-weight: 700;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(15, 23, 42, 0.25);
  flex-shrink: 0;
}

.line {
  display: inline-block;
  width: 14px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

.legend-label {
  flex: 1;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-count {
  font-variant-numeric: tabular-nums;
  color: #64748b;
  font-size: 11px;
}

.reset-btn {
  margin-top: 12px;
  width: 100%;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}

.reset-btn:hover {
  background: #e2e8f0;
}

#graph {
  position: relative;
  background:
    linear-gradient(0deg, rgba(15, 23, 42, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.025) 1px, transparent 1px) #ffffff;
  background-size: 24px 24px;
}

#graph .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 32px;
  text-align: center;
  pointer-events: none;
}

#detail h2 {
  font-size: 14px;
  margin: 0 0 2px 0;
  word-break: break-word;
}

#detail .subtitle {
  font-size: 11px;
  color: #64748b;
  margin-bottom: 6px;
  font-style: italic;
}

#detail .subtitle .role {
  font-style: normal;
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 10px;
  color: #475569;
}

#detail .meta {
  margin-bottom: 12px;
  font-size: 11px;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#detail .summary {
  font-size: 12px;
  line-height: 1.5;
  color: #1f2937;
  margin: 8px 0;
}

#detail .working-answer {
  font-size: 12px;
  line-height: 1.5;
  background: #f0fdf4;
  border-left: 3px solid #16a34a;
  padding: 8px 10px;
  margin: 10px 0;
  border-radius: 0 4px 4px 0;
}

#detail .working-answer strong {
  color: #166534;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#detail .prose-link {
  display: inline-block;
  margin: 6px 0 12px;
  padding: 4px 10px;
  background: #0f172a;
  color: #f1f5f9;
  font-size: 11px;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 500;
}

#detail .prose-link:hover {
  background: #1e293b;
}

.status-badge {
  display: inline-block;
  background: #e2e8f0;
  color: #334155;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.status-badge.status-val-open,
.status-badge.status-val-not-yet-drafted,
.status-badge.status-val-skeleton {
  background: #fef3c7;
  color: #92400e;
}
.status-badge.status-val-in-workshop,
.status-badge.status-val-working,
.status-badge.status-val-provisionally-resolved {
  background: #dbeafe;
  color: #1e40af;
}
.status-badge.status-val-drafted,
.status-badge.status-val-resolved,
.status-badge.status-val-load-bearing {
  background: #dcfce7;
  color: #166534;
}
.status-badge.status-val-superseded,
.status-badge.status-val-retired {
  background: #f3f4f6;
  color: #6b7280;
}
.status-badge.status-val-restricted {
  background: #fee2e2;
  color: #991b1b;
}
.status-badge.status-val-external {
  background: #ede9fe;
  color: #5b21b6;
}

.type-badge.tiny {
  font-size: 9px;
  padding: 1px 4px;
  margin-right: 0;
}

#detail dl.props {
  margin: 8px 0;
  padding: 8px 0;
  border-top: 1px solid #f1f5f9;
  border-bottom: 1px solid #f1f5f9;
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 4px 8px;
  font-size: 11px;
}

#detail dl.props dt {
  color: #64748b;
  font-family: ui-monospace, "SF Mono", monospace;
}

#detail dl.props dd {
  margin: 0;
  word-break: break-word;
}

#detail dl.props dd code {
  font-size: 10px;
  margin-right: 4px;
  display: inline-block;
  margin-bottom: 2px;
}

#detail .neighbours-section {
  margin-top: 14px;
}

#detail .neighbours-section h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #475569;
  margin: 0 0 6px 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

#detail .neighbours-section .dir-count {
  font-size: 9px;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

#detail .predicate-group {
  margin-bottom: 8px;
}

#detail .predicate-group h4 {
  font-size: 10px;
  margin: 4px 0;
  color: #64748b;
  font-family: ui-monospace, "SF Mono", monospace;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

#detail .predicate-group .pred-count {
  font-size: 9px;
  color: #cbd5e1;
  font-weight: 400;
}

#detail .predicate-group ul {
  list-style: none;
  margin: 0;
  padding: 0 0 0 0;
}

#detail .predicate-group li {
  margin: 2px 0;
}

#detail .node-link {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  padding: 3px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  text-align: left;
  line-height: 1.3;
}

#detail .node-link:hover {
  background: #f1f5f9;
  border-color: #e2e8f0;
}

#detail .node-link .node-link-label {
  flex: 1;
  word-break: break-word;
  color: #1f2937;
}

.type-badge {
  display: inline-block;
  background: #e2e8f0;
  color: #334155;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  margin-right: 4px;
  letter-spacing: 0.02em;
}

#detail code {
  font-size: 11px;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", monospace;
}

#detail table {
  width: 100%;
  border-collapse: collapse;
}

#detail th,
#detail td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 11px;
  vertical-align: top;
  word-break: break-word;
}

#detail th {
  color: #64748b;
  font-weight: 500;
  width: 90px;
  font-family: ui-monospace, "SF Mono", monospace;
  white-space: nowrap;
}

#detail .empty {
  color: #94a3b8;
  font-style: italic;
  font-size: 12px;
}

.empty-graph {
  color: #94a3b8;
  font-size: 13px;
}

.empty-graph.error {
  color: #dc2626;
  font-family: ui-monospace, monospace;
  padding: 20px;
  text-align: center;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
  }
  aside {
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
  }
  aside#detail {
    border-left: none;
    border-top: 1px solid #e2e8f0;
  }
  #search {
    width: 160px;
  }
}
