/* Tool-specific layout tokens */
.json-tree-page {
  --tree-indent: 21px;
  --tree-row-height: 29px;
  --tree-detail-height: 270px;
  --tree-toggle-size: 23px;
  --tree-detail-action-height: 27px;
  --tree-detail-action-radius: 4px;
  --tree-detail-card-radius: 5px;
  --tree-stat-card-radius: 6px;
  --tree-match-accent: #e6a700;
  --tree-detail-columns: repeat(2, minmax(0, 1fr));
  --tree-stat-columns: repeat(4, minmax(0, 1fr));
  --tree-about-columns: repeat(2, minmax(0, 1fr));
}

/* Progress and toolbars */
.json-tree-page .json-tree-progress {
  width: 90px;
  height: 8px;
  accent-color: var(--json-primary);
}

.json-tree-page .json-tree-search-toolbar,
.json-tree-page .json-tree-expand-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-block-end: 1px solid var(--json-border);
}

.json-tree-page .json-tree-search-field {
  display: inline-flex;
  flex: 1 1 360px;
  align-items: center;
  gap: 8px;
}

.json-tree-page .json-tree-search-field input {
  width: 100%;
}

.json-tree-page :is(.json-tree-search-field, .json-tree-search-count) {
  color: var(--json-muted);
}

.json-tree-page .json-tree-search-count {
  min-width: 62px;
  text-align: end;
}

.json-tree-page .json-tree-drop-zone.is-dragging {
  box-shadow: inset 0 0 0 3px var(--json-focus);
}

.json-tree-page .json-tree-result-pane {
  min-width: 0;
}

/* Tree workspace */
.json-tree-page .json-tree-browser-body {
  display: grid;
  grid-template-rows: minmax(180px, 1fr) auto;
  height: var(--json-editor-height);
  min-height: 0;
  background: var(--editor-background);
}

.json-tree-page .json-tree-scroll {
  min-height: 0;
  padding: 8px 0;
  overflow: auto;
  outline: none;
}

.json-tree-page :is(.json-tree-root, .json-tree-group) {
  min-width: max-content;
  margin: 0;
  padding: 0;
  list-style: none;
}

.json-tree-page .json-tree-group {
  margin-inline-start: var(--tree-indent);
}

.json-tree-page .json-tree-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 100%;
  min-height: var(--tree-row-height);
  padding: 2px 12px 2px 6px;
  border: 1px solid transparent;
  color: var(--editor-text);
  cursor: default;
  white-space: nowrap;
}

.json-tree-page .json-tree-row:hover {
  background: color-mix(in srgb, var(--json-focus) 9%, var(--editor-background));
}

.json-tree-page .json-tree-row:focus-visible {
  border-color: var(--json-focus);
  outline: none;
}

.json-tree-page .json-tree-row.is-selected {
  background: color-mix(in srgb, var(--json-focus) 19%, var(--editor-background));
}

.json-tree-page .json-tree-row.is-match {
  box-shadow: inset 3px 0 var(--tree-match-accent);
}

.json-tree-page .json-tree-toggle {
  display: inline-grid;
  width: var(--tree-toggle-size);
  height: var(--tree-toggle-size);
  flex: 0 0 var(--tree-toggle-size);
  padding: 0;
  border: 0;
  color: var(--editor-muted);
  background: transparent;
  font: inherit;
  place-items: center;
  cursor: pointer;
}

.json-tree-page .json-tree-toggle:disabled {
  opacity: 0.55;
  cursor: default;
}

.json-tree-page .json-tree-key {
  color: var(--token-key);
  font-weight: 650;
}

/* Node syntax and states */
.json-tree-page :is(
  .json-tree-colon,
  .json-tree-type,
  .json-tree-range-row,
  .json-tree-empty,
  .json-tree-detail-empty
) {
  color: var(--editor-muted);
}

.json-tree-page .json-tree-type {
  margin-inline-start: 4px;
  font-size: 0.78em;
}

.json-tree-page .json-tree-value--string {
  color: var(--token-string);
}

.json-tree-page .json-tree-value--number {
  color: var(--token-number);
}

.json-tree-page :is(.json-tree-value--boolean, .json-tree-value--null) {
  color: var(--token-boolean);
}

.json-tree-page :is(.json-tree-value--object, .json-tree-value--array) {
  color: var(--editor-muted);
}

.json-tree-page .json-tree-range-row {
  font-style: italic;
}

.json-tree-page .json-tree-empty {
  display: grid;
  min-height: 100%;
  margin: 0;
  padding: 18px;
  place-items: center;
  text-align: center;
}

/* Selected-node details */
.json-tree-page .json-tree-detail {
  max-height: var(--tree-detail-height);
  padding: 10px 12px 12px;
  overflow: auto;
  border-block-start: 1px solid var(--editor-border);
  background: var(--editor-heading);
}

.json-tree-page .json-tree-detail-heading,
.json-tree-page .json-tree-detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.json-tree-page .json-tree-detail-heading {
  justify-content: space-between;
  margin-block-end: 8px;
}

.json-tree-page .json-tree-detail-heading h4 {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.json-tree-page .json-tree-detail-action {
  min-height: var(--tree-detail-action-height);
  padding: 3px 7px;
  border: 1px solid var(--editor-border);
  border-radius: var(--tree-detail-action-radius);
  color: var(--editor-text);
  background: var(--editor-background);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.json-tree-page .json-tree-detail-action:disabled {
  color: var(--editor-muted);
  cursor: not-allowed;
  opacity: 0.65;
}

.json-tree-page .json-tree-detail-empty {
  margin: 0;
}

.json-tree-page .json-tree-detail-grid {
  display: grid;
  grid-template-columns: var(--tree-detail-columns);
  gap: 7px;
  margin: 0;
}

.json-tree-page .json-tree-detail-card {
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--editor-border);
  border-radius: var(--tree-detail-card-radius);
  background: var(--editor-background);
}

.json-tree-page .json-tree-detail-grid .json-tree-detail-wide {
  grid-column: 1 / -1;
}

.json-tree-page .json-tree-detail-grid :is(dt, dd),
.json-tree-page .json-tree-stats-grid :is(dt, dd) {
  margin: 0;
}

.json-tree-page .json-tree-detail-grid :is(dt, dd) {
  overflow-wrap: anywhere;
}

.json-tree-page .json-tree-detail-grid dt {
  color: var(--editor-muted);
  font-size: 10px;
}

.json-tree-page .json-tree-detail-grid dd {
  max-height: 100px;
  overflow: auto;
  white-space: pre-wrap;
}

/* Statistics, warnings, and operation messages */
.json-tree-page .json-tree-stats-grid {
  display: grid;
  grid-template-columns: var(--tree-stat-columns);
  gap: 10px;
  margin: 0;
  padding: 14px;
}

.json-tree-page .json-tree-stat-card {
  padding: 10px;
  border: 1px solid var(--json-border);
  border-radius: var(--tree-stat-card-radius);
  background: var(--json-control);
}

.json-tree-page .json-tree-stats dt {
  color: var(--json-muted);
  font-size: 12px;
}

.json-tree-page .json-tree-stats dd {
  color: var(--json-text);
  font-size: 18px;
  font-weight: 700;
}

.json-tree-page .json-tree-warnings ul {
  margin: 0;
  padding: 12px 32px;
  color: var(--json-warning);
}

.json-tree-page .json-tree-message {
  margin: 0 0 14px;
  padding: 11px 13px;
  border: 1px solid var(--json-border);
  border-radius: var(--json-radius-small);
  background: var(--json-message-bg);
}

.json-tree-page .json-tree-message[data-type="success"] {
  color: var(--json-success);
}

.json-tree-page .json-tree-message[data-type="warning"] {
  color: var(--json-warning);
}

.json-tree-page .json-tree-message[data-type="error"] {
  border-color: var(--json-error-border);
  color: var(--json-error);
  background: var(--json-error-background);
}

.json-tree-page .json-format-about-grid {
  display: grid;
  grid-template-columns: var(--tree-about-columns);
  gap: 24px;
}

/* Responsive layout */
@media (max-width: 900px) {
  .json-tree-page {
    --tree-stat-columns: repeat(2, minmax(0, 1fr));
  }

  .json-tree-page .json-format-workspace {
    grid-template-columns: 1fr;
  }

  .json-tree-page .json-format-editor-pane + .json-format-editor-pane {
    border-block-start: 1px solid var(--editor-border);
    border-inline-start: 0;
  }

}

@media (max-width: 620px) {
  .json-tree-page {
    --tree-detail-columns: 1fr;
    --tree-stat-columns: 1fr;
    --tree-about-columns: 1fr;
  }

  .json-tree-page .json-tree-search-field,
  .json-tree-page .json-tree-search-toolbar .json-format-setting,
  .json-tree-page .json-tree-search-toolbar .json-format-select,
  .json-tree-page .json-tree-search-toolbar .json-format-button {
    width: 100%;
  }

  .json-tree-page .json-tree-detail-grid .json-tree-detail-wide {
    grid-column: auto;
  }
}

/* Motion preferences */
@media (prefers-reduced-motion: reduce) {
  .json-tree-page * {
    scroll-behavior: auto !important;
  }
}
