body {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

#app { display: contents; }

.app-sidebar {
  grid-column: 1;
  grid-row: 1;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--card);
  border-right: 1px solid var(--border);
}

.app-main {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.hub-link {
  display: block;
  padding: 12px 16px;
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--purple);
  color: white;
  font-weight: 800;
  font-size: 11px;
}

.brand-title { font-weight: 800; }
.brand-role { color: var(--text-dim); font-size: 11px; margin-top: 2px; }

.section-toggle,
.module-link,
.top-actions button,
.module-error button {
  font: inherit;
}

.top-actions button:disabled {
  cursor: wait;
  opacity: .72;
}

.section-toggle {
  width: 100%;
  min-height: 40px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
}

.section-toggle:hover { color: var(--text); background: var(--bg); }
.nav-section.collapsed .section-items { display: none; }
.nav-section.collapsed .chevron { transform: rotate(-90deg); }
.chevron { display: inline-block; width: 24px; text-align: center; transition: transform .15s; }

.module-link {
  width: 100%;
  min-height: 32px;
  padding: 7px 16px 7px 24px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  text-align: left;
  font-size: 12px;
}

.module-link:hover { background: var(--bg); color: var(--text); }
.module-link.active {
  color: var(--purple);
  background: rgba(124, 110, 249, .12);
  border-left: 3px solid var(--purple);
  padding-left: 21px;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 800;
}

h1 { margin: 2px 0 0; font-size: 18px; }
.top-actions { display: flex; gap: 8px; }
.top-actions button,
.module-error button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
}

.module-host { padding: 20px 20px 12px; }
.module-state,
.module-error {
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
}

.module-error {
  border: 1px solid rgba(239, 68, 68, .25);
  background: rgba(239, 68, 68, .08);
  border-radius: 8px;
}

.module-error-title { color: var(--text); font-weight: 800; margin-bottom: 6px; }
.module-error-message { margin-bottom: 14px; }

.sources-sidebar {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 90vw);
  padding: 20px;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -16px 0 40px rgba(0,0,0,.28);
  z-index: 20;
}

.sources-sidebar.open { display: block; }
.source-list { display: grid; gap: 10px; margin-top: 16px; }
.source-section-title {
  margin-top: 18px;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}
.lineage-table-wrap {
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.lineage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.lineage-table th,
.lineage-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.lineage-table th {
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
}
.lineage-table td:nth-child(3),
.lineage-table td:nth-child(4) {
  color: var(--text-dim);
}
.module-sources-inline {
  margin: 0 20px 24px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}
.inline-sources-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.inline-sources-header h2 {
  margin: 2px 0 0;
  font-size: 14px;
}
.inline-sources-header button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
}
.source-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.source-error { border-color: rgba(239, 68, 68, .55); }
.source-label { font-size: 13px; font-weight: 800; }
.source-path {
  margin-top: 3px;
  color: var(--text-dim);
  font-size: 11px;
  word-break: break-all;
}
.source-meta {
  display: grid;
  gap: 4px;
  align-content: center;
  justify-items: end;
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
}
.panel-close {
  float: right;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  .app-sidebar,
  .app-main { grid-column: 1; }
  .app-sidebar { position: relative; height: auto; max-height: 45vh; }
}
