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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  background: #1a1a2e;
}

#cy {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* --- Shared: hidden utility --- */

.hidden {
  display: none !important;
}

/* --- Shared: type colors (injected at runtime from TYPE_COLORS in graph.js) --- */

/* --- Shared: type badge (pill label) --- */

.type-badge {
  display: inline-block;
  height: 18px;
  line-height: 14px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
}

/* --- Shared: node badge (small shape with letter) --- */

.badge-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.node-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.node-badge.badge-class {
  border-radius: 2px;
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
}

.node-badge.badge-class > span {
  display: block;
  transform: rotate(-45deg);
}

.node-badge.badge-instance {
  border-radius: 0;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
  width: 16px;
  height: 14px;
  padding-top: 3px;
}

.node-badge.badge-axiom {
  border-radius: 0;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  width: 18px;
  height: 18px;
}

/* --- Shared: small action buttons --- */

.btn-action {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 3px;
  font-size: 14px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-action-add {
  background: #e8f0fe;
  color: #4a90d9;
}

.btn-action-add:hover {
  background: #4a90d9;
  color: #fff;
}

.btn-action-remove {
  background: #fde8e8;
  color: #d9534f;
}

.btn-action-remove:hover {
  background: #d9534f;
  color: #fff;
}

.btn-action-remove-red {
  background: rgba(231, 76, 60, 0.15);
  color: #e74c3c;
}

.btn-action-remove-red:hover {
  background: #e74c3c;
  color: #fff;
}

/* Variant: auto-push to the right in a flex row */
.btn-action-right {
  margin-left: auto;
}

/* --- Shared: section header (flex row with label + optional controls) --- */

.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.section-header.header-loading {
  pointer-events: none;
}

/* --- Shared: section label (uppercase text) --- */

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: #000;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.section-label-flex {
  flex: 1;
}

/* --- Shared: panel section separator --- */

#inventory,
#selection-summary,
.detail-connections,
.detail-tools {
  margin-top: 10px;
  border-top: 1px solid #eee;
  padding-top: 8px;
}

/* --- Shared: list status (loading / error) --- */

.list-status {
  font-size: 12px;
  padding: 2px 0;
}

.list-status-loading {
  color: #999;
}

.list-status-error {
  color: #c00;
}

/* --- Shared: list item base (inventory + connection nodes) --- */

.list-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  border-radius: 4px;
  transition: background 0.1s;
  user-select: none;
}

.list-item.in-graph:hover {
  background: #e8f0fe;
}

.list-item.selected {
  background: #d0e4ff;
}

.list-item.selected:hover {
  background: #b8d4f8;
}

/* --- Shared: list item selection toggle --- */

.list-select-toggle {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid #bbb;
  box-sizing: border-box;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}

.list-select-toggle:hover {
  border-color: #4a90d9;
}

.list-item.selected .list-select-toggle {
  background: #4a90d9;
  border-color: #4a90d9;
}

.list-select-toggle.list-select-disabled {
  background: #ccc;
  border-color: #ccc;
  cursor: default;
  pointer-events: none;
}

/* --- Shared: group header selection toggle (none / partial / all) --- */

.group-select-toggle {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid #bbb;
  box-sizing: border-box;
  cursor: pointer;
  margin-right: 2px;
  margin-top: 1px;
  position: relative;
  transition: background 0.1s, border-color 0.1s;
}

.group-select-toggle:hover {
  border-color: #4a90d9;
}

.group-select-toggle.group-select-all {
  background: #4a90d9;
  border-color: #4a90d9;
}

.group-select-toggle.group-select-partial {
  border-color: #4a90d9;
}

.group-select-toggle.group-select-partial::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 1.5px;
  background: #4a90d9;
  border-radius: 1px;
}

.group-select-toggle.group-select-disabled {
  background: #ccc;
  border-color: #ccc;
  cursor: default;
  pointer-events: none;
}

/* --- Shared: toggle active state (ALL button + union/inter switch) --- */

.conn-show-all-toggle.active,
.conn-mode-switch button.active {
  background: #4a90d9;
  color: #fff;
  border-color: #4a90d9;
}

.conn-show-all-toggle.active:hover,
.conn-mode-switch button.active:hover {
  background: #3a7bc8;
}

/* --- Shared: accordion group --- */

.acc-group {
  margin-bottom: 4px;
}

.acc-header {
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}

.acc-header:hover {
  opacity: 0.7;
}

.acc-toggle {
  display: inline-block;
  font-size: 9px;
  width: 12px;
  text-align: center;
  flex-shrink: 0;
}

.conn-arrow {
  display: inline-block;
  width: 1em;
  text-align: center;
}

.acc-body.hidden {
  display: none;
}

/* --- Control Panel --- */

#controls {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 10;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  padding: 16px;
  width: 400px;
  max-height: calc(100vh - 76px);
  overflow-y: auto;
  font-size: 13px;
}

#controls h3 {
  font-size: 15px;
  margin-bottom: 2px;
  color: #333;
}

#meta-info {
  font-size: 11px;
  color: #999;
  margin-bottom: 10px;
  line-height: 1.4;
}

.control-group {
  margin-bottom: 10px;
}

.control-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #666;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.control-row {
  display: flex;
  gap: 6px;
}

#search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 6px;
  outline: none;
  transition: border-color 0.2s;
}

#search-input:focus {
  border-color: #4a90d9;
}

select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
  cursor: pointer;
}

button {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

#btn-search {
  background: #4a90d9;
  color: #fff;
}

#btn-search:hover {
  background: #3a7bc8;
}


/* --- History Controls (bottom-left) --- */

#history-controls {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 10;
  display: flex;
  gap: 6px;
}

#history-controls button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: #fff;
  color: #555;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  transition: background 0.15s;
}

#history-controls button:hover:not(:disabled) {
  background: #eee;
}

#history-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

/* --- Viewport Controls --- */

#viewport-controls {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  gap: 6px;
}

#viewport-controls button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: #fff;
  color: #555;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  transition: background 0.15s;
}

#viewport-controls button:hover {
  background: #eee;
}

#viewport-controls button.active {
  background: #4a90d9;
  color: #fff;
}

#viewport-controls button.active:hover {
  background: #3a7bc8;
}

#viewport-controls button.hidden {
  display: none;
}

#viewport-controls select {
  height: 36px;
  padding: 0 24px 0 10px;
  border: none;
  border-radius: 8px;
  background: #fff;
  color: #555;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23555'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

#viewport-controls #btn-rerun-layout {
  width: auto;
  padding: 0 10px;
}

/* --- Hamburger Menu --- */

#hamburger-wrapper {
  position: relative;
}

#btn-hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
}

.hamburger-icon {
  width: 14px;
  height: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hamburger-icon span {
  display: block;
  height: 1.5px;
  background: #555;
  border-radius: 1px;
}

#hamburger-menu {
  position: absolute;
  bottom: 42px;
  right: 0;
  background: #fff;
  border-radius: 8px;
  padding: 0;
  min-width: 140px;
  overflow: hidden;
}

#hamburger-menu.hidden {
  display: none;
}

#hamburger-menu .menu-item {
  display: block;
  width: 100%;
  padding: 5px 12px;
  border: none;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: #333;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

#hamburger-menu .menu-item:hover:not(:disabled) {
  background: #e8f0fe;
}

#hamburger-menu .menu-item:disabled {
  color: #aaa;
  cursor: default;
}

/* --- Inventory --- */

#inventory.hidden {
  display: none;
}

#inventory .section-header {
  margin-top: 6px;
}

#inventory > div:first-child .section-header {
  margin-top: 0;
}

#inventory .list-items {
  padding-left: 14px;
}

.list-item-label {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.list-item-suffix {
  flex-shrink: 0;
  color: #999;
  font-size: 11px;
  margin-right: 2px;
}

/* --- Search Results --- */

#search-results {
  margin-top: 8px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 6px;
}

#search-results.hidden {
  display: none;
}

#results-list {
  list-style: none;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 12px;
  cursor: default;
}

.result-item:last-child {
  border-bottom: none;
}

.result-item:hover {
  background: #f7f9fc;
}

.result-name {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  color: #333;
}

.result-type {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 8px;
  color: #fff;
  flex-shrink: 0;
}

.result-score {
  font-size: 10px;
  color: #888;
  flex-shrink: 0;
  margin-left: 4px;
}

.search-load-more {
  justify-content: center;
  cursor: pointer;
  color: #333;
}

.search-load-more:hover:not(.disabled) {
  background: #f7f9fc;
}

.search-load-more.disabled {
  color: #888;
  cursor: default;
}

#status {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
  min-height: 16px;
}

/* --- Details Panel --- */

#details {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  padding: 14px;
  width: 400px;
  max-height: calc(100vh - 76px);
  overflow-y: auto;
  font-size: 13px;
}

#details.hidden {
  display: none;
}

#selection-summary:empty {
  display: none;
}

.sel-pills {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 18px;
}

.sel-pill {
  height: 18px;
  line-height: 14px;
}

.sel-pill::after {
  content: attr(data-count);
  margin-left: 6px;
  padding-left: 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.4);
}

#detail-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}

#detail-pager:empty {
  display: none;
}

.pager-btn {
  padding: 0;
  border: none;
  background: none;
  color: #999;
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
}

.pager-btn:hover {
  color: #333;
}

.pager-text {
  font-size: 12px;
  color: #666;
  min-width: 50px;
  text-align: center;
}

#details-header {
  margin-bottom: 10px;
}

#details-title {
  font-weight: 700;
  font-size: 14px;
  color: #333;
}

#details-body .detail-field {
  margin-bottom: 8px;
}

.detail-field-header {
  display: flex;
  align-items: center;
  line-height: 1.5;
}

.detail-copy-btn {
  margin-left: auto;
  padding: 0 5px;
  border: none;
  border-radius: 3px;
  background: none;
  color: #aaa;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  line-height: 18px;
  height: 18px;
}

.detail-copy-btn:hover {
  background: #e8f0fe;
  color: #4a90d9;
}

#details-body .detail-value {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 12px;
  color: #333;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f5f5f5;
  padding: 4px 6px;
  border-radius: 4px;
  max-height: 120px;
  overflow-y: auto;
}

/* --- Connection list in details panel --- */

.detail-tools .section-header {
  margin-bottom: 8px;
}

.section-header-spaced {
  padding-top: 4px;
}

.conn-show-all-toggle {
  font-size: 10px;
  padding: 0 6px;
  border: 1px solid #aaa;
  border-radius: 8px;
  background: #fff;
  color: #666;
  cursor: pointer;
  line-height: 16px;
  height: 18px;
}

.conn-show-all-toggle:hover {
  background: #eee;
}

.conn-mode-switch {
  display: inline-flex;
  border: 1px solid #aaa;
  border-radius: 8px;
  overflow: hidden;
  height: 18px;
}

.conn-mode-switch button {
  font-size: 10px;
  padding: 0 5px;
  border: none;
  background: #fff;
  color: #666;
  cursor: pointer;
  line-height: 16px;
  height: 100%;
}

.conn-mode-switch button:hover {
  background: #eee;
}

.conn-mode-switch button:disabled {
  cursor: default;
  opacity: 0.5;
}

.conn-mode-switch button:disabled:hover {
  background: #fff;
}

.conn-group .acc-header,
.tool-group .acc-header {
  min-height: 22px;
  margin-bottom: 4px;
}

.tool-summary {
  font-size: 12px;
  color: #555;
  margin-bottom: 4px;
}

.tool-add-all {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #e8f0fe;
  color: #4a90d9;
  cursor: pointer;
}

.tool-add-all:hover:not(:disabled) {
  background: #4a90d9;
  color: #fff;
}

.tool-add-all:disabled {
  opacity: 0.5;
  cursor: default;
}

.tool-depth-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.tool-depth-row .tool-summary {
  flex: 1;
  margin-bottom: 0;
}

/* Inventory list-items: always in-graph, less indentation */
#inventory .list-item {
  color: #333;
  padding: 2px 0 2px 6px;
  cursor: default;
}

/* Connection list-items: more indentation, grey when not in graph */
.conn-group .list-items {
  display: flex;
  flex-direction: column;
}

.conn-group .list-item {
  color: #999;
  padding: 2px 0 2px 18px;
  cursor: default;
}

.conn-group .list-item.in-graph {
  color: #333;
}

/* Add-all button in connection group headers */

.conn-add-all {
  margin-left: auto;
  padding: 0 5px;
  border: none;
  border-radius: 3px;
  background: #e8f0fe;
  color: #4a90d9;
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
  height: 18px;
  line-height: 18px;
  text-transform: none;
  letter-spacing: 0;
  flex-shrink: 0;
}

.conn-add-all:hover {
  background: #4a90d9;
  color: #fff;
}

.conn-load-more,
.conn-show-hidden {
  display: block;
  width: fit-content;
  margin: 4px auto 0;
  font-size: 11px;
  color: #4a90d9;
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  background: #e8f0fe;
  cursor: pointer;
}

.conn-load-more:hover,
.conn-show-hidden:hover {
  background: #4a90d9;
  color: #fff;
}

.similarity-bar {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  flex-shrink: 0;
}

.similarity-track {
  display: inline-block;
  width: 40px;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
}

.similarity-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
}
