:root {
  color-scheme: dark;

  --fcs-bg: #1e1e1e;
  --fcs-header: #2d2d2d;
  --fcs-border: #3e3e3e;
  --fcs-highlight: #007acc; /* VS Code blue, or use Kenshi orange */
  --fcs-text: #ccc;
  --fcs-text-muted: #888;
  --fcs-active-text: #fff;
  --fcs-hover: rgb(255 255 255 / 5%);
  --fcs-control-hover: rgb(255 255 255 / 7%);
  --fcs-status: #9ecb9e;
  --fcs-warning: #e6b566;
  --fcs-error: #ef8f8f;
  --fcs-notice-border: #744;
  --fcs-notice-bg: #3a2525;
  --fcs-notice-text: #efb0b0;
  --fcs-reference-border: #333;
  --fcs-reference-heading: #aaa;
  --fcs-reference-id: #666;
  --fcs-search-bg: #111;
  --fcs-search-border: #444;
  --fcs-search-text: #fff;
  --fcs-key: #569cd6;
  --fcs-value: #ce9178;
  --fcs-empty: #555;
}

:root[data-theme='light'] {
  color-scheme: light;

  --fcs-bg: #f3f3f3;
  --fcs-header: #e4e4e4;
  --fcs-border: #c4c4c4;
  --fcs-highlight: #007acc;
  --fcs-text: #242424;
  --fcs-text-muted: #616161;
  --fcs-active-text: #fff;
  --fcs-hover: rgb(0 0 0 / 5%);
  --fcs-control-hover: rgb(0 0 0 / 7%);
  --fcs-status: #2e7d32;
  --fcs-warning: #7a5200;
  --fcs-error: #b3261e;
  --fcs-notice-border: #c96b6b;
  --fcs-notice-bg: #fdecec;
  --fcs-notice-text: #8b1a1a;
  --fcs-reference-border: #c4c4c4;
  --fcs-reference-heading: #555;
  --fcs-reference-id: #616161;
  --fcs-search-bg: #fff;
  --fcs-search-border: #aaa;
  --fcs-search-text: #242424;
  --fcs-key: #005a9e;
  --fcs-value: #9b3f21;
  --fcs-empty: #777;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body,
html {
  height: 100%;
  width: 100%;
  margin: 0;
  overflow: hidden; /* Prevent body scroll, we handle inner scrolls */
  background-color: var(--fcs-bg);
  color: var(--fcs-text);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 13px; /* Dense information */
}

/* Layout Grid */
.fcs-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.fcs-header {
  height: 40px;
  background-color: var(--fcs-header);
  border-bottom: 1px solid var(--fcs-border);
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(18rem, 32vw, 32rem) minmax(0, 1fr);
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  flex-shrink: 0;
}

.header-context {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 1rem;
}

.header-context strong {
  flex: 0 0 auto;
}

.path-display {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-controls {
  display: flex;
  flex-shrink: 0;
  gap: 12px;
  align-items: center;
  justify-self: end;
}

.global-search {
  position: relative;
  min-width: 0;
}

#global-search-input {
  width: 100%;
  height: 30px;
  margin: 0;
  padding: 0 2rem 0 2.25rem;
  border: 1px solid var(--fcs-search-border);
  background-position: left 0.75rem center;
  background-size: 1rem auto;
  background-repeat: no-repeat;
  background-color: var(--fcs-search-bg);
  color: var(--fcs-search-text);
  font-size: 0.9rem;
}

.global-search-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  overflow: hidden;
  border: 1px solid var(--fcs-border);
  border-radius: 3px;
  background-color: var(--fcs-bg);
  box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
}

.global-search-panel[hidden] {
  display: none;
}

.global-search-status,
.global-search-summary {
  padding: 0.65rem 0.75rem;
  color: var(--fcs-text-muted);
  font-size: 0.85rem;
}

.global-search-summary {
  border-top: 1px solid var(--fcs-border);
  text-align: right;
}

.global-search-status:empty,
.global-search-summary:empty {
  display: none;
}

.global-search-status.error {
  color: var(--fcs-error);
}

.global-search-results {
  max-height: min(55vh, 32rem);
  overflow-y: auto;
}

.global-search-option {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-bottom: 1px solid var(--fcs-border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--fcs-text);
  font: inherit;
  text-align: left;
}

.global-search-option:hover,
.global-search-option.active {
  background-color: var(--fcs-control-hover);
}

.global-search-option.active {
  outline: 1px solid var(--fcs-highlight);
  outline-offset: -1px;
}

.global-search-result-name,
.global-search-result-meta {
  display: block;
  overflow-wrap: anywhere;
}

.global-search-result-name {
  color: var(--fcs-highlight);
}

.global-search-result-name.unnamed {
  color: var(--fcs-text-muted);
  font-style: italic;
}

.global-search-result-meta {
  margin-top: 0.15rem;
  color: var(--fcs-text-muted);
  font-size: 0.8rem;
}

.ecosystem-links {
  display: flex;
  gap: 4px;
  align-items: center;
  margin: 0;
}

.ecosystem-links a,
.theme-toggle {
  display: inline-flex;
  width: 32px;
  min-width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
  color: var(--fcs-text-muted);
}

.ecosystem-links a:hover,
.ecosystem-links a:focus-visible,
.theme-toggle:hover,
.theme-toggle:focus-visible {
  background-color: var(--fcs-control-hover);
  color: var(--fcs-highlight);
}

.ecosystem-icon,
.theme-icon {
  display: block;
  width: 18px;
  height: 18px;
  background-color: currentcolor;
  mask: var(--ecosystem-icon) center / contain no-repeat;
}

.icon-wiki {
  --ecosystem-icon: url('/assets/icons/wiki-icon.svg');
}

.icon-map {
  --ecosystem-icon: url('/assets/icons/map-icon.svg');
}

.icon-database {
  --ecosystem-icon: url('/assets/icons/database-icon.svg');
}

.icon-chat {
  --ecosystem-icon: url('/assets/icons/chat-icon.svg');
}

.icon-sun {
  --ecosystem-icon: url('/assets/icons/sun-icon.svg');
}

.icon-moon {
  --ecosystem-icon: url('/assets/icons/moon-icon.svg');
}

.manifest-status {
  min-inline-size: 12rem;
  color: var(--fcs-status);
  font-size: 0.85rem;
  text-align: right;
  white-space: nowrap;
}

.manifest-status.loading {
  color: var(--fcs-text-muted);
}

.manifest-status.warning {
  color: var(--fcs-warning);
}

.manifest-status.error,
.data-error {
  color: var(--fcs-error);
}

.fcs-workspace {
  display: grid;
  grid-template-columns: 250px 350px 1fr; /* Tree | List | Inspector */
  flex-grow: 1;
  min-height: 0;
  overflow: hidden;
}

.pane-tree {
  grid-row: 1;
  grid-column: 1;
}

.pane-list {
  grid-row: 1;
  grid-column: 2;
}

.pane-inspector {
  grid-row: 1;
  grid-column: 3;
}

/* Generic Pane Styling */
.fcs-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--fcs-border);
  background-color: var(--fcs-bg);
  height: 100%;
  margin: 0;

  /* NEW: This is the magic bullet for Grid/Flex scrolling */
  min-height: 0;

  /* OLD: You had min-width, keep that too */
  min-width: 0;
}

.pane-header {
  flex: 0 0 auto;
  padding: 8px;
  background-color: var(--fcs-header);
  border-bottom: 1px solid var(--fcs-border);
  font-weight: 600;
  color: var(--fcs-text-muted);
}

.pane-footer {
  flex: 0 0 auto;
  padding: 4px 8px;
  background-color: var(--fcs-header);
  border-top: 1px solid var(--fcs-border);
  font-size: 0.85em;
  color: var(--fcs-text-muted);
}

.list-content,
.inspector-scroll {
  overflow-y: auto;
  flex: 1 1 0;
  min-height: 0;
}

.reference-notice {
  flex: 0 0 auto;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--fcs-notice-border);
  background-color: var(--fcs-notice-bg);
  color: var(--fcs-notice-text);
}

.reference-notice[hidden] {
  display: none;
}

.fcs-workspace[aria-busy='true'] .fcs-pane {
  opacity: 0.72;
}

/* Tree & List Items */
.tree-item,
.list-item {
  padding: 4px 12px;
  cursor: pointer;
  color: var(--fcs-text);
  border-bottom: 1px solid transparent;
}

.tree-item {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 8px;
  align-items: start;
}

.item-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.item-string-id {
  justify-self: end;
  font-size: 0.8em;
  opacity: 0.5;
  white-space: nowrap;
}

.tree-item:hover,
.list-item:hover {
  background-color: var(--fcs-hover);
}

.tree-item.active,
.list-item.active {
  background-color: var(--fcs-highlight);
  color: var(--fcs-active-text);
}

.inspector-content {
  padding: 1rem;
}

.inspector-title {
  margin-bottom: 0.5rem;
  color: var(--pico-primary);
}

.inspector-string-id {
  margin-bottom: 1rem;
  color: var(--fcs-reference-id);
  font-family: monospace;
}

.relationship-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  margin-top: 1.5rem;
  border-top: 1px solid var(--fcs-border);
}

.relationship-column {
  min-width: 0;
  padding-top: 1rem;
}

.relationship-column:first-child {
  padding-right: 1rem;
}

.relationship-column + .relationship-column {
  padding-left: 1rem;
  border-left: 1px solid var(--fcs-border);
}

.relationship-column > h3 {
  margin: 0 0 0.75rem;
  color: var(--fcs-reference-heading);
  font-size: 1rem;
}

.relationship-empty {
  margin: 0;
  color: var(--fcs-text-muted);
  font-style: italic;
}

.reference-group {
  margin-top: 1rem;
}

.reference-group:first-of-type {
  margin-top: 0;
}

.reference-group h4 {
  margin: 0 0 0.5rem;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--fcs-reference-border);
  color: var(--fcs-reference-heading);
}

.reference-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.reference-list > li {
  display: block;
  margin: 0;
  padding: 0;
  list-style: none;
}

.reference-list > li::marker {
  content: '';
}

.ref-link {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: baseline;
  justify-content: flex-start;
  gap: 0.35rem;
  margin: 0;
  padding: 3px 0;
  border: 0;
  border-bottom: 1px solid var(--fcs-hover);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.reference-value-grid[data-value-columns='1'] {
  grid-template-columns: minmax(0, 1fr) minmax(3.5rem, max-content);
}

.reference-value-grid[data-value-columns='2'] {
  grid-template-columns: minmax(0, 1fr) repeat(2, minmax(3.5rem, max-content));
}

.reference-value-grid[data-value-columns='3'] {
  grid-template-columns: minmax(0, 1fr) repeat(3, minmax(3.5rem, max-content));
}

.reference-value-header,
.ref-link.reference-value-grid {
  display: grid;
  column-gap: 0.5rem;
}

.reference-value-header {
  align-items: end;
  padding: 0 0 3px;
  color: var(--fcs-reference-id);
  font-size: 0.8rem;
  font-weight: 600;
}

.reference-value-heading,
.reference-value {
  justify-self: end;
  white-space: nowrap;
}

.reference-value {
  color: var(--fcs-value);
  font-family: monospace;
  font-variant-numeric: tabular-nums;
}

.reference-target {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 0.35rem;
}

.reference-target small {
  flex: 0 0 auto;
  white-space: nowrap;
}

.referrer-link {
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
}

.referrer-unavailable {
  display: flex;
  width: 100%;
  min-width: 0;
  padding: 3px 0;
  border-bottom: 1px solid var(--fcs-hover);
  color: var(--fcs-text-muted);
  cursor: default;
}

.ref-link:hover,
.ref-link:focus-visible {
  background: transparent;
}

.reference-name {
  min-width: 0;
  color: var(--fcs-highlight);
  overflow-wrap: anywhere;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.2s;
}

.referrer-unavailable .reference-name {
  color: inherit;
  text-decoration: none;
}

.ref-link:hover .reference-name,
.ref-link:focus-visible .reference-name {
  text-decoration-color: var(--fcs-highlight);
}

.ref-link small {
  color: var(--fcs-reference-id);
}

.referrer-metadata {
  max-width: 100%;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.packed-color {
  display: inline-flex;
  max-width: 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.5rem;
  font-variant-numeric: tabular-nums;
}

.color-decimal,
.color-hex,
.color-rgb,
.color-separator {
  white-space: nowrap;
}

.color-separator {
  color: var(--fcs-text-muted);
  user-select: none;
}

.color-swatch {
  display: inline-block;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border: 1px solid var(--fcs-text-muted);
  vertical-align: -2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Search Input Override */
#item-search {
  height: 30px;
  font-size: 0.9em;
  padding: 0 8px;
  margin: 0;
  background-color: var(--fcs-search-bg);
  border: 1px solid var(--fcs-search-border);
  color: var(--fcs-search-text);
}

/* Inspector Table (Reused from your existing CSS concept) */
.fcs-table {
  width: 100%;
  border-collapse: collapse;
  font-family: monospace;
}

.fcs-table td,
.fcs-table th {
  padding: 6px 12px;
  border-bottom: 1px solid var(--fcs-border);
  text-align: left;
}

.fcs-key {
  color: var(--fcs-key);
  width: 30%;
  vertical-align: top;
}

.fcs-key.fcs-stat-good {
  color: var(--fcs-status);
}

.fcs-key.fcs-stat-bad {
  color: var(--fcs-error);
}

.fcs-val {
  color: var(--fcs-value);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.fcs-val.fcs-boolean-true {
  color: var(--fcs-status);
}

.fcs-val.fcs-boolean-false {
  color: var(--fcs-error);
}

.not-applicable-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  background-color: var(--fcs-text-muted);
  mask: url('/assets/icons/not-applicable.svg') center / contain no-repeat;
  vertical-align: middle;
}

.empty-state {
  padding: 2rem;
  color: var(--fcs-empty);
  text-align: center;
}

.loading-indicator::before {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-right: 0.5rem;
  border: 2px solid var(--fcs-border);
  border-top-color: var(--fcs-highlight);
  border-radius: 50%;
  content: '';
  vertical-align: -0.1rem;
  animation: fcs-spin 0.8s linear infinite;
}

.registry-error {
  display: grid;
  gap: 0.75rem;
  justify-items: center;
}

.retry-button {
  width: auto;
  margin: 0;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

@keyframes fcs-spin {
  to {
    transform: rotate(360deg);
  }
}
