/* Artiverse dataset preview - styles
 * Restrained design: neutrals + single accent, no gradients/glass/emoji.
 * Tight density without feeling cramped. Inspired by Linear / HF Datasets.
 */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-alt: #f5f5f6;
  --surface-hover: #f0f0f2;
  --border: #e6e7ea;
  --border-strong: #d6d8dd;
  --text: #16181c;
  --text-mute: #5a5f68;
  --text-dim: #898e98;
  --accent: #3854c8;
  --accent-soft: #eef0fb;
  --accent-strong: #2b3fa3;
  --danger: #b9261c;
  --danger-soft: #fbeae8;
  --warning: #8a5500;
  --warning-soft: #fbf2dc;
  --success: #1a6b40;
  --success-soft: #e3f1e8;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --topbar-h: 52px;
  --sidebar-w: 232px;
  --info-w: 420px;

  --shadow-sm: 0 1px 0 rgba(20,24,30,0.04);
  --shadow-md: 0 4px 12px rgba(20,24,30,0.06), 0 1px 2px rgba(20,24,30,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}
button { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--font-mono); }

.hidden { display: none !important; }

/* --- top bar ----------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(360px, auto) 1fr minmax(180px, auto);
  align-items: center;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
}
.brand-link:hover { text-decoration: none; }
.brand-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.brand-tag {
  font-size: 11px;
  color: var(--text-dim);
  padding-left: 8px;
  border-left: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: stretch;
  gap: 18px;
  height: 100%;
}
.topnav {
  display: flex;
  align-items: stretch;
  gap: 4px;
  margin-left: 6px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}
.topnav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  color: var(--text-mute);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border-radius: 0;
}
.topnav-link:hover { color: var(--text); text-decoration: none; }
.topnav-link.active {
  color: var(--accent-strong);
  font-weight: 600;
}
.topnav-link.active::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}
.topbar-search {
  display: flex;
  justify-content: center;
}
.topbar-search input {
  width: min(560px, 100%);
  height: 32px;
  padding: 0 12px;
  font: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--text);
}
.topbar-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.dataset-meta {
  color: var(--text-mute);
  font-size: 12px;
  text-align: right;
}

/* --- layout: views ----------------------------------------------------- */

main#app-main {
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}
.view {
  height: 100%;
  display: grid;
}

/* --- gallery ----------------------------------------------------------- */

#gallery-view {
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100%;
  min-height: 0;
}
.filters {
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px 24px;
  min-width: 0;
}
.filter-block { margin-bottom: 20px; }
.filter-block h3 {
  margin: 0 4px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.filter-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.filter-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  transition: background-color 60ms linear;
  min-width: 0;
  text-decoration: none;
}
.filter-item:hover { background: var(--surface-hover); text-decoration: none; }
.filter-item:hover, .filter-item:focus { color: var(--text); }
.filter-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 500;
}
.filter-item.active:hover { color: var(--accent-strong); }
.filter-item > span:first-child {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}
.filter-item .count {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 11px;
  padding-top: 2px;
}
.filter-item.active .count { color: var(--accent-strong); }
#filter-sort {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font: inherit;
  color: var(--text);
}

.gallery {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-height: 0;
  height: 100%;
}
.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.gallery-summary {
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.gallery-pager {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(208px, 1fr));
  grid-auto-rows: max-content;
  gap: 18px;
  align-content: start;
  align-items: start;
}
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  transition: border-color 80ms linear, box-shadow 80ms linear, transform 80ms ease;
}
.card:hover { text-decoration: none; color: var(--text); }
.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.card-thumb-wrap {
  position: relative;
  width: 100%;
  padding-top: 100%;
  background-color: #ebedf1;
  background-image:
    linear-gradient(45deg, #e2e4e9 25%, transparent 25%, transparent 75%, #e2e4e9 75%),
    linear-gradient(45deg, #e2e4e9 25%, transparent 25%, transparent 75%, #e2e4e9 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
  overflow: hidden;
}
.card-thumb {
  position: absolute;
  inset: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  object-fit: contain;
  display: block;
}
.card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--border);
}
.card-category {
  font-size: 12px;
  color: var(--text-mute);
  text-transform: capitalize;
}
.card-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
  gap: 6px;
  color: var(--text-dim);
  font-size: 11px;
}
.card-badge {
  display: inline-flex;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-mute);
  font-size: 10px;
  letter-spacing: 0.02em;
}
.card-badge.solo { font-variant-numeric: tabular-nums; }
.empty-state {
  grid-column: 1 / -1;
  padding: 60px 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* --- templates view ---------------------------------------------------- */

#templates-view {
  grid-template-columns: 280px 1fr;
  grid-template-rows: 100%;
  min-height: 0;
}
.template-search {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  margin-bottom: 8px;
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.template-list .filter-item {
  text-transform: capitalize;
}
.template-detail {
  overflow-y: auto;
  padding: 24px 28px 40px;
  background: var(--bg);
  min-height: 0;
}
.template-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-dim);
}
.template-header {
  margin-bottom: 16px;
}
.template-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-transform: capitalize;
  margin: 0 0 4px;
}
.template-subtitle {
  color: var(--text-mute);
  font-size: 12px;
  text-transform: capitalize;
}
.template-gloss {
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  margin: 8px 0 24px;
  max-width: 880px;
}
.template-section h3 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.template-section + .template-section { margin-top: 28px; }
.template-parts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.template-part {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
}
.template-part-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.template-part-name {
  font-size: 13px;
  font-weight: 600;
  text-transform: capitalize;
}
.template-part-name code {
  font-size: 11px;
  color: var(--text-mute);
  font-weight: 400;
}
.template-part-gloss {
  color: var(--text-mute);
  font-size: 12px;
  line-height: 1.45;
  margin: 4px 0 8px;
}
.template-part-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 11px;
}
.template-part-meta .chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-mute);
  border: 1px solid var(--border);
}
.template-part-meta .chip.dep {
  background: var(--surface);
  color: var(--text-mute);
}
.template-part-meta .chip.joint-revolute { background: #eaf3ff; color: #2b66b8; border-color: transparent; }
.template-part-meta .chip.joint-prismatic { background: #eaf8ee; color: var(--success); border-color: transparent; }
.template-part-meta .chip.joint-continuous { background: #f3eafa; color: #774ca8; border-color: transparent; }
.template-part-meta .chip.joint-fixed { background: var(--surface-alt); color: var(--text-dim); border-color: transparent; }
.template-part-meta .chip.joint-screw, .template-part-meta .chip.joint-cylindrical, .template-part-meta .chip.joint-ball, .template-part-meta .chip.joint-floating {
  background: #fff5e6; color: var(--warning); border-color: transparent;
}
.template-examples {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.template-example {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
}
.template-example:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); text-decoration: none; }
.template-example .thumb {
  position: relative;
  width: 100%;
  padding-top: 100%;
  background-color: #ebedf1;
  background-image:
    linear-gradient(45deg, #e2e4e9 25%, transparent 25%, transparent 75%, #e2e4e9 75%),
    linear-gradient(45deg, #e2e4e9 25%, transparent 25%, transparent 75%, #e2e4e9 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
  overflow: hidden;
}
.template-example .thumb img {
  position: absolute;
  inset: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  object-fit: contain;
}
.template-example .meta {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-mute);
}

/* --- detail view ------------------------------------------------------- */

#detail-view {
  grid-template-rows: 48px 1fr;
}
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-mute);
  font-size: 12px;
}
.breadcrumb-link { color: var(--accent); }
.breadcrumb-current { color: var(--text); }
.breadcrumb-sep { color: var(--text-dim); }
.model-id-code {
  font-size: 11px;
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text);
}
.detail-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-mute);
  font-size: 12px;
}
.nav-pos { font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }
.kbd-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
  font-size: 11px;
  margin-right: 12px;
}
.kbd-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 0 4px;
  height: 18px;
  background: var(--surface-alt);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
  font-family: var(--font-sans);
  font-size: 10.5px;
  color: var(--text-mute);
}
@media (max-width: 1180px) { .kbd-hint { display: none; } }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr var(--info-w);
  height: 100%;
  min-height: 0;
}

/* viewer */
.viewer-pane {
  display: flex;
  flex-direction: column;
  background: var(--surface-alt);
  border-right: 1px solid var(--border);
  min-width: 0;
}
.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.viewer-toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.viewer-toolbar-right { margin-left: auto; }
.viewer-status {
  font-size: 11px;
  color: var(--text-dim);
}
.viewer-canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
#viewer-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.viewer-overlay {
  position: absolute;
  left: 14px;
  top: 14px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-mute);
  max-width: 280px;
  pointer-events: none;
}
.viewer-overlay strong { color: var(--text); }
.viewer-hover {
  position: absolute;
  pointer-events: none;
  background: rgba(20,24,30,0.92);
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transform: translate(8px, -100%);
  white-space: nowrap;
  font-family: var(--font-mono);
}
.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 245, 246, 0.78);
  pointer-events: none;
  z-index: 5;
}
.viewer-loading-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow-md);
}
.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* segmented control */
.seg-toggle {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  color: var(--text-mute);
  user-select: none;
}
.seg-toggle:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg-toggle:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left-width: 0; }
.seg-toggle input { display: none; }
.seg-toggle:has(input:checked) {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
  z-index: 1;
}

/* buttons */
.toggle-btn, .ghost-btn {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-mute);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.toggle-btn:hover, .ghost-btn:hover { background: var(--surface-hover); color: var(--text); }
.toggle-btn[data-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}
.primary-btn {
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.primary-btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* info pane */
.info-pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  min-width: 0;
  overflow: hidden;
}
.info-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.info-titles { min-width: 0; flex: 1 1 auto; }
.info-category {
  font-size: 16px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: -0.005em;
  line-height: 1.2;
}
.info-source {
  font-size: 11px;
  color: var(--text-mute);
  margin-top: 3px;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info-dimensions {
  text-align: right;
  flex: 0 0 auto;
  font-size: 10.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.3;
}
.info-dimensions strong {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}
.template-link {
  display: inline-block;
  margin-bottom: 4px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent-strong) !important;
  font-size: 10.5px;
  text-transform: none;
  letter-spacing: 0;
  text-decoration: none;
}
.template-link:hover { background: var(--accent); color: #fff !important; text-decoration: none; }

.info-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}
.metric { padding: 12px 16px; }
.metric + .metric { border-left: 1px solid var(--border); }
.metric-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.metric-value {
  margin-top: 2px;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* materials strip */
.materials-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.material-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
}
.material-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

/* tabs */
.tabs {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
}
.tab {
  position: relative;
  background: transparent;
  border: none;
  padding: 10px 8px;
  font-size: 12px;
  color: var(--text-mute);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  font-weight: 500;
}
.tab.active::after {
  content: "";
  position: absolute;
  inset: auto 4px -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}
.tab-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 0 6px;
  height: 16px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.tab-panels {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.tab-panel {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
}
.tab-panel.active { display: block; }
.panel-body {
  padding: 12px 16px 20px;
  font-size: 12.5px;
}

/* joints panel */
.joint-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.joint-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
}
.joint-group-head .pid-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-mute);
  font-weight: 400;
}
.joint-group.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.joint-group.active .joint-group-head { background: var(--accent-soft); color: var(--accent-strong); }
.joint-item {
  padding: 8px 10px;
}
.joint-item + .joint-item { border-top: 1px solid var(--border); }
.joint-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}
.joint-item-head .joint-type {
  font-size: 11px;
  color: var(--text-mute);
  background: var(--surface-alt);
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.joint-meta {
  margin: 4px 0 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}
.joint-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.joint-control input[type=range] {
  flex: 1;
  accent-color: var(--accent);
}
.joint-value {
  min-width: 60px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
}
.joint-extras {
  display: flex;
  align-items: center;
  gap: 4px;
}
.joint-range {
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* parts table */
.parts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.parts-table th {
  text-align: left;
  font-weight: 500;
  color: var(--text-mute);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.parts-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.parts-table tr:hover td { background: var(--surface-alt); cursor: pointer; }
.parts-table .label { text-transform: capitalize; }
.parts-table .material-cell {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.parts-table .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.parts-table .text-mono {
  font-family: var(--font-mono);
  font-size: 11px;
}
.parts-table tr.active td { background: var(--accent-soft); }
.parts-table-compact { table-layout: fixed; }
.parts-table-compact td,
.parts-table-compact th {
  padding: 6px 6px;
  vertical-align: top;
}
.parts-table-compact .col-pid { width: 30px; }
.parts-table-compact .col-label { width: 70px; }
.parts-table-compact .col-material { width: auto; }
.parts-table-compact .col-material .material-cell {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.parts-table-compact .col-material .submat {
  margin-top: 2px;
  font-size: 10.5px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.parts-table-compact .col-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* materials breakdown */
.materials-legend {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.materials-legend .row {
  display: grid;
  grid-template-columns: 18px 1fr auto auto;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.materials-legend-materials-only .row {
  grid-template-columns: 18px 1fr;
}
.materials-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.08);
}

/* renders grid */
.renders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
}
.renders-grid figure {
  margin: 0;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: zoom-in;
}
.renders-grid img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  aspect-ratio: 1 / 1;
}
.renders-section + .renders-section { margin-top: 18px; }
.renders-section h4 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 600;
}

/* provenance */
.prov-block { margin-bottom: 16px; }
.prov-block h4 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 600;
}
.prov-json {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: pre-wrap;
  overflow-x: auto;
  color: var(--text);
  max-height: 320px;
  overflow-y: auto;
}

/* complaints */
.complaint-form {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.complaint-form .form-row { display: grid; gap: 4px; }
.complaint-form .form-row.split {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.complaint-form label {
  font-size: 11px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.complaint-form select,
.complaint-form input,
.complaint-form textarea {
  width: 100%;
  padding: 6px 8px;
  font: inherit;
  font-size: 12.5px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.complaint-form textarea { min-height: 80px; resize: vertical; line-height: 1.45; }
.complaint-form input:focus,
.complaint-form textarea:focus,
.complaint-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.complaint-form .form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.complaint-confirmation {
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid transparent;
  font-size: 12px;
}
.complaint {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface);
  margin-bottom: 8px;
}
.complaint-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-mute);
  margin-bottom: 4px;
}
.complaint-kind {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-transform: capitalize;
}
.severity-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.severity-blocker { background: var(--danger-soft); color: var(--danger); }
.severity-major { background: var(--warning-soft); color: var(--warning); }
.severity-minor { background: var(--accent-soft); color: var(--accent-strong); }
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-alt);
  color: var(--text-mute);
  border: 1px solid var(--border);
}
.status-acknowledged { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.status-resolved { background: var(--success-soft); color: var(--success); border-color: transparent; }
.complaint-message {
  margin: 4px 0 6px;
  white-space: pre-wrap;
  color: var(--text);
  font-size: 12.5px;
}
.complaint-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.complaint-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.complaint-actions button {
  height: 22px;
  padding: 0 6px;
  font-size: 10px;
  border-radius: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-mute);
  cursor: pointer;
}
.complaint-actions button:hover { background: var(--surface-hover); color: var(--text); }

/* light-table list / empty messages */
.muted { color: var(--text-mute); font-size: 12px; }
.dim { color: var(--text-dim); font-size: 12px; }

/* --- graphs view -------------------------------------------------------- */
#graphs-view {
  grid-template-columns: 280px 1fr;
  grid-template-rows: 100%;
  min-height: 0;
}
.graphs-main {
  overflow-y: auto;
  padding: 24px 28px 40px;
  min-width: 0;
}
.graphs-header { margin-bottom: 18px; }
.graphs-header .breadcrumbs { margin-bottom: 8px; }
.graphs-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 40px 8px;
  color: var(--text-mute);
  font-size: 13px;
}
.graph-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.graph-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}
.graph-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}
.graph-card-preview {
  height: 200px;
  width: 100%;
  background:
    linear-gradient(0deg, rgba(0,0,0,0.015), rgba(0,0,0,0.015)),
    var(--surface-alt, #fafbfc);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.graph-card-body { padding: 12px 14px 14px; }
.graph-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.gc-stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.graph-card-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.gc-chip {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--surface-alt, #f1f3f6);
  color: var(--text-dim);
  white-space: nowrap;
}
.gc-chip b { color: var(--text); }
.gc-chip.dim { opacity: 0.65; }
.graph-group-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) 1.4fr;
  gap: 20px;
  align-items: start;
}
.graph-group-preview-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
}
.graph-group-canvas {
  height: 420px;
}
.graph-group-models { min-width: 0; }
@media (max-width: 980px) {
  .graph-group-layout { grid-template-columns: 1fr; }
  .graph-group-preview-pane { position: static; }
}

/* graph panel */
.tab-panel[data-panel="graph"] { overflow: hidden; }
#panel-graph.panel-graph {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 12px 16px 16px;
  box-sizing: border-box;
  gap: 10px;
}
.graph-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.graph-toggle { display: inline-flex; }
.graph-toggle .seg-toggle[data-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
}
.graph-fit { padding: 4px 10px; font-size: 11px; }
.graph-hint { font-size: 11px; color: var(--text-mute); margin-left: auto; }
.graph-empty { padding: 16px; }
.graph-canvas {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: grab;
  user-select: none;
}
.graph-canvas.is-panning { cursor: grabbing; }
.graph-svg {
  display: block;
  width: 100%;
  height: 100%;
}
.graph-node { cursor: pointer; }
.graph-node rect {
  fill: #ffffff;
  stroke: #c2c8d3;
  stroke-width: 1;
  transition: fill 0.12s, stroke 0.12s;
}
.graph-node:hover rect {
  fill: #eef3fb;
  stroke: #4f6ea3;
  stroke-width: 1.4;
}
.graph-node.is-virtual rect {
  fill: #fff5e6;
  stroke: #d39a4a;
  stroke-dasharray: 3 2;
}
.graph-node.is-affordance rect {
  fill: #f0f7ee;
  stroke: #8db680;
}
.graph-node-label {
  font: 600 11px var(--font-sans, sans-serif);
  fill: #1d2330;
  pointer-events: none;
}
.graph-node-pid {
  font: 10px var(--font-mono, monospace);
  fill: #6a7384;
  pointer-events: none;
}

/* graph legend */
.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  align-items: center;
  font-size: 11px;
  color: var(--text-dim);
  flex: 0 0 auto;
}
.graph-legend .gl-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
}
.graph-legend .gl-title {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10px;
  color: var(--text-mute);
}
.graph-legend .gl-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.graph-legend .gl-line {
  width: 18px;
  height: 0;
  border-top: 2px solid var(--c, #9aa3b2);
  display: inline-block;
}
.graph-legend .gl-line.dashed { border-top-style: dashed; }
.graph-legend .gl-box {
  width: 14px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
  background: #ffffff;
  border: 1px solid #c2c8d3;
}
.graph-legend .gl-box.is-virtual {
  background: #fff5e6;
  border-color: #d39a4a;
  border-style: dashed;
}
.graph-legend .gl-box.is-affordance {
  background: #f0f7ee;
  border-color: #8db680;
}

/* graphs-view card controls */
.graphs-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 20px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #16181c;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}

/* scrollbars */
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.18);
  border-radius: 5px;
  border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.28); }
*::-webkit-scrollbar-track { background: transparent; }

/* responsive */
@media (max-width: 1200px) {
  :root { --info-w: 340px; }
}
@media (max-width: 980px) {
  :root { --sidebar-w: 200px; --info-w: 320px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
