/* Shared compact popup and settings treatments. Keep form controls readable. */
:root {
  --popup-heading-bg: #edf4ff;
  --popup-heading-text: #254e7b;
  --popup-line: #d4e1f0;
  --popup-radius: 7px;
}

/* All settings subsections receive a visible heading surface, in every theme. */
body #app :is(.control-page, .plugin-settings, .settings-panel, .project-utility-settings)
  :is(.settings-compact-section, .settings-subsection, .nested-setting) > :is(summary, .nested-setting-head),
body #app :is(.settings-compact-section, .settings-subsection) > summary,
body #app :is(.control-page, .plugin-settings, .settings-panel, .project-utility-settings)
  :is(.settings-module-head, .settings-subsection-label, .studio-field-list-heading),
body #app .studio-selected-settings > summary {
  background: var(--popup-heading-bg) !important;
  color: var(--popup-heading-text) !important;
  border-bottom: 1px solid var(--popup-line) !important;
  border-radius: 4px 4px 0 0;
  font-weight: 600 !important;
}

body :is(.tree-node-editor-dialog, .tree-header-editor, .tree-figure-editor,
  .tree-range-label-editor, .columns-popover, .cm-action-dialog, .analysis-help-dialog) {
  border-color: var(--popup-line);
  border-radius: var(--popup-radius);
  color: var(--text, #27364d);
  font: 12px/1.4 var(--app-font-family, 'Segoe UI', sans-serif);
  box-shadow: 0 12px 34px #1c2b422e;
}
body :is(.tree-node-editor-dialog, .tree-header-editor, .tree-figure-editor,
  .tree-range-label-editor) > header,
body .columns-popover .columns-panel-head {
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  background: var(--popup-heading-bg);
  color: var(--popup-heading-text);
  border-bottom: 1px solid var(--popup-line);
}
body :is(.tree-node-editor-dialog, .tree-header-editor, .tree-figure-editor,
  .tree-range-label-editor) > header > :is(strong, h2, h3) {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 650;
}
body :is(.tree-node-editor-dialog, .tree-header-editor, .tree-figure-editor,
  .tree-range-label-editor) > header > button,
body .columns-popover [data-close-columns] {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 3px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #526780;
  cursor: pointer;
}
body :is(.tree-node-editor-dialog, .tree-header-editor, .tree-figure-editor,
  .tree-range-label-editor) button:hover:not(:disabled),
body .columns-popover button:hover:not(:disabled) { background: #e6eefb; }
body :is(.tree-node-editor-dialog, .columns-popover) :is(button, input, select):focus-visible {
  outline: 2px solid #4275c5;
  outline-offset: 1px;
}

body #app :is(.control-page, .plugin-settings, .settings-panel) .settings-subsection-label {
  padding: 4px 6px !important;
  margin-block: 5px;
}
body #app .studio-field-list-heading .settings-subsection-label { margin: 0; border: 0 !important; }

body .tree-node-editor-dialog {
  width: min(450px, calc(100vw - 20px));
  max-height: calc(100dvh - 24px);
  box-sizing: border-box;
}
body .tree-node-editor-body { padding: 7px 10px; max-height: calc(100dvh - 125px); }
body .tree-node-field {
  grid-template-columns: minmax(100px, .85fr) minmax(0, 1.4fr);
  gap: 8px;
  margin: 4px 0;
  min-height: 27px;
}
body .tree-node-editor-dialog [hidden] { display: none !important; }
body .tree-node-editor-dialog :is(input, select, textarea, button) { font: inherit; box-sizing: border-box; }
body .tree-node-editor-dialog :is(input:not([type='checkbox']), select, textarea) {
  min-height: 26px;
  padding: 3px 6px;
  border: 1px solid #c8d3e3;
  border-radius: 4px;
}
body .tree-node-editor-dialog input[data-color-control] { width: 42px; justify-self: start; }
body .tree-node-editor-dialog input[type='checkbox'] { width: 14px; height: 14px; margin: 0; }
body .tree-node-editor-dialog > footer {
  padding: 6px 10px;
  gap: 6px;
  border-top: 1px solid var(--popup-line);
  background: #f6f9fd;
}
body .tree-node-editor-dialog :is(footer, .tree-node-multi) button {
  min-height: 25px;
  padding: 3px 8px;
  border: 1px solid #c8d3e3;
  border-radius: 4px;
  color: inherit;
  background: #fff;
}
body .tree-node-editor-dialog footer button.primary { background: #2d6bb0; color: white; border-color: #2d6bb0; }
body .tree-node-editor-error:empty { display: none; }
body .tree-node-multi > summary { padding: 4px 6px; margin: 5px 0; background: #edf4ff; border-radius: 4px; }
body .tree-node-segment { grid-template-columns: minmax(0, 1fr) 25px 25px 34px 24px; gap: 4px; margin: 4px 0; }
body .tree-node-segment input[data-color-control] { width: 34px; }
body .tree-node-segment > button { padding: 0; width: 24px; }
body .tree-segment-format {
  position: relative;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  margin: 0;
  border: 1px solid #ccd8e8;
  border-radius: 4px;
  color: #49617d;
  cursor: pointer;
}
body .tree-segment-format input { position: absolute; opacity: 0; }
body .tree-segment-format:has(input:checked) { color: #2454b8; background: #e7efff; border-color: #7d9fde; }
body .tree-segment-format:has(input:focus-visible) { outline: 2px solid #4275c5; outline-offset: 1px; }

/* Columns use one compact row per field; long names remain available on hover. */
body .columns-popover.global-floating-panel.metadata-only-columns {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 480px !important;
  min-width: 0 !important;
  max-width: calc(100vw - 16px) !important;
  max-height: calc(100dvh - 24px);
  padding: 6px 6px 22px;
  overflow: hidden !important;
}
body .metadata-only-columns > :not(.columns-list) { flex-shrink: 0; }
body .metadata-only-columns .columns-list { flex: 1 1 auto; min-height: 0; overflow: auto; }
body .metadata-only-columns.is-resized .columns-row > span:first-child { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
body .metadata-only-columns .metadata-columns-resize { position: absolute; bottom: 1px; right: 2px; width: 20px; height: 20px; padding: 0; border: 0; background: transparent; color: #708399; cursor: nwse-resize; touch-action: none; }
body .metadata-only-columns .columns-panel-head { margin: -6px -6px 5px; }
body .metadata-only-columns :is(.columns-head-row, .columns-row) {
  grid-template-columns: minmax(0, 1fr) 54px 82px 92px !important;
  gap: 6px !important;
  min-height: 27px;
  padding: 1px 3px;
}
body .metadata-only-columns .columns-head-row { min-height: 34px; text-align: center; font-size: 9px; }
body .metadata-only-columns .columns-head-row > b {
  display: block;
  width: auto;
  min-width: 0;
  padding: 2px 4px;
  white-space: normal;
  overflow-wrap: normal;
  line-height: 12px;
  letter-spacing: 0;
  text-align: center;
}
body .metadata-only-columns .columns-head-row > b:first-of-type { white-space: nowrap; }
body .metadata-only-columns .columns-head-row > :first-child { text-align: left; }
body .metadata-only-columns .columns-row > span:first-child { font-size: 11px; }
body .metadata-only-columns .metadata-excluded-note { display: inline; margin-left: 5px; font-size: 9px; }
body .metadata-only-columns .column-order-buttons { width: 92px; min-width: 92px; gap: 1px; }
body .metadata-only-columns .column-order-buttons button {
  flex: 0 0 22px;
  width: 22px;
  height: 23px;
  padding: 3px;
  border: 0;
  background: transparent;
}
body .metadata-only-columns .column-order-buttons .ui-icon { width: 15px; height: 15px; }
body .metadata-only-columns .metadata-derived-note { background: none; padding: 0 2px; font-size: 10px; }
body .metadata-only-columns input[type='checkbox'] { margin: 0; width: 13px; height: 13px; }
body .metadata-only-columns .columns-panel-actions { gap: 4px; margin: 5px 0 0; flex-wrap: wrap; }
body .metadata-only-columns .columns-panel-actions button { min-height: 25px; padding: 3px 6px; font: inherit; font-size: 11px; border-radius: 4px; }
body .metadata-only-columns .metadata-schema-actions { justify-content: flex-end; margin: 3px 0 5px; }
body .metadata-only-columns .metadata-schema-actions button { flex: 0 0 auto; }
body .metadata-only-columns .concise-note { margin: 5px 2px; font-size: 10px; line-height: 1.4; }

/* Compact confirmation and help dialogs share the same spacing, preserving danger colors. */
body .cm-action-dialog { padding: 14px; }
body .cm-action-dialog-header { margin-bottom: 9px; gap: 8px; }
body .cm-action-dialog h3 { font-size: 14px; }
body .cm-action-dialog p { margin-bottom: 10px; font-size: 12px; line-height: 1.5; }
body .cm-action-dialog input { padding: 5px 7px; min-height: 28px; border-radius: 4px; }
body .cm-action-dialog .cm-action-dialog-buttons { padding-top: 9px; margin-top: 10px; gap: 6px; }
body .cm-action-dialog .cm-action-dialog-buttons button { min-width: 70px; min-height: 28px; padding: 4px 10px; border-radius: 4px; }
body .analysis-help-dialog { padding: 14px; }
body .analysis-help-dialog h2 { font-size: 14px; }
body .analysis-help-dialog > p { margin-top: 10px; font-size: 12px; line-height: 1.5; }

/* Match the boxless, compact figure toolbars, with an expandable inline search. */
body #app #metadataView .data-grid-toolbar { gap: 3px; min-height: 32px; padding: 3px 6px; }
body #app #metadataView .data-grid-toolbar .icon-only-action {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 27px;
  min-width: 27px;
  height: 26px;
  min-height: 26px;
  padding: 4px;
  border: 0 !important;
  border-radius: 4px;
  background: transparent !important;
  box-shadow: none !important;
  color: #526780;
}
body #app #metadataView .data-grid-toolbar .icon-only-action:is(:hover, [aria-expanded='true']):not(:disabled) {
  background: #eaf0fc !important;
  color: #3459d4;
}
body #app #metadataView .data-grid-toolbar .icon-only-action:disabled { opacity: .4; }
body #app #metadataView .data-grid-toolbar .ui-icon { width: 16px; height: 16px; }
body #app #metadataView .data-grid-toolbar .workspace-save-btn { width: 37px; }
body #app #metadataView .data-grid-toolbar .save-chevron { width: 10px; }
body #app #metadataView .metadata-search-control { display: inline-flex; align-items: center; flex: 0 0 auto; gap: 2px; }
body #app #metadataView #metadataSearchInput { width: 180px; min-width: 0; height: 25px; padding: 3px 6px; font-size: 11px; border: 1px solid #c8d3e3; border-radius: 4px; }
body #app #metadataView #metadataSearchInput[hidden] { display: none !important; }
body #app #metadataView .metadata-link-column-control { gap: 4px; }
body #app #metadataView .metadata-link-column-control select { width: 115px; min-width: 70px; max-width: 140px; height: 25px; padding: 2px 20px 2px 5px; font-size: 11px; }
body #app #metadataView #metadataSourceSelect { box-sizing: border-box; field-sizing: content; width: auto; min-width: 0; max-width: none; height: 25px; min-height: 25px; line-height: normal; text-overflow: ellipsis; }
.metadata-column-menu { overflow: auto; }
.metadata-column-menu > strong { display: block; padding: 5px 8px; overflow-wrap: anywhere; }
.metadata-column-menu > button { width: 100%; text-align: left; }
body #metadataFilterPanel.metadata-filter-editor { box-sizing: border-box; font-size: 12px; }
body #metadataFilterPanel.metadata-filter-editor:not(.is-collapsed) { width: 260px; min-width: 260px; padding: 8px; overflow: auto; }
.metadata-filter-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.metadata-filter-heading button { border: 0; background: transparent; padding: 0 5px; font-size: 18px; }
.metadata-filter-hint { margin: 4px 0 8px; color: var(--muted); font-size: 11px; }
.metadata-filter-rules { display: grid; gap: 7px; padding: 1px; }
.metadata-filter-rule { display: grid; grid-template-columns: minmax(0, 1fr) 25px; align-items: start; gap: 4px; padding-bottom: 7px; border-bottom: 1px solid var(--border); }
.metadata-filter-rule > select:first-child { grid-column: 1; grid-row: 1; }
.metadata-filter-rule > select:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
.metadata-filter-rule > button { grid-column: 2; grid-row: 1; }
.metadata-filter-rule :is(select, input:not([type=checkbox]), summary) { box-sizing: border-box; width: 100%; min-width: 0; min-height: 27px; padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); font: inherit; color: var(--text); }
.metadata-filter-rule > button { padding: 2px 5px; min-height: 27px; }
.metadata-filter-rule-value { min-width: 0; grid-column: 1 / -1; grid-row: 3; }
.metadata-filter-value-picker summary { cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metadata-filter-value-picker > input { margin: 4px 0; }
.metadata-filter-value-list { max-height: 150px; overflow: auto; border: 1px solid var(--border); border-radius: 4px; padding: 3px; }
.metadata-filter-value-list label { display: flex; flex-direction: row; align-items: center; gap: 5px; margin: 0; padding: 3px; font-size: 11px; }
.metadata-filter-value-list label span { flex: 1; overflow-wrap: anywhere; }
.metadata-filter-value-list input { margin: 0; flex: 0 0 auto; width: 14px; height: 14px; padding: 0; }
.metadata-filter-value-list small { color: var(--muted); }
.metadata-filter-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding-top: 7px; }
.metadata-filter-footer:last-child { margin-top: 7px; border-top: 1px solid var(--border); }
.metadata-filter-footer button { min-height: 26px; padding: 3px 8px; font: inherit; }
.metadata-filter-editor :is(.metadata-filter-footer button, .metadata-filter-rule > button) { border: 1px solid var(--border); border-radius: 4px; background: var(--panel); color: var(--text); cursor: pointer; }
.metadata-filter-editor :is(.metadata-filter-footer button, .metadata-filter-rule > button):hover:not(:disabled) { background: #edf4fc; border-color: #9ab9d9; }
.metadata-filter-editor .metadata-filter-footer button.primary-btn { background: #2f6fa8; border-color: #2f6fa8; color: white; }
.metadata-filter-footer output { width: 100%; text-align: left; color: var(--muted); font-size: 11px; }
.metadata-filter-footer .primary-btn { margin-left: auto; }
body #app #metadataView .toolbar-divider { height: 17px; margin: 0 4px; }
body #app #metadataView .tool-count { position: absolute; top: -1px; right: -2px; font-size: 9px; min-width: 12px; }

body .tree-figure-editor { width: min(480px, calc(100vw - 20px)); padding: 10px; }
body .tree-figure-editor > header { display: flex; margin: -10px -10px 8px; }
body .tree-figure-editor > header h3 { flex: 1; }
body .tree-figure-editor .tree-figure-editor-fields { gap: 5px 8px; }
body .tree-figure-editor .tree-figure-editor-fields label { gap: 3px; font-size: 11px; }
body .tree-figure-editor .tree-figure-editor-fields :is(input:not([type='checkbox']), select) { min-height: 25px; padding: 3px 5px; }
body .tree-figure-editor .tree-figure-editor-fields input[type='checkbox'] { width: 14px; height: 14px; }
body .tree-figure-editor > footer { padding: 7px 0 0; margin-top: 8px; border-top: 1px solid var(--popup-line); }
body .tree-figure-editor > footer button { min-height: 25px; padding: 3px 8px; font: inherit; }

body #app #metadataView .data-grid-toolbar .icon-only-action[aria-expanded='true']::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: calc(50% - 3px);
  width: 6px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}
/* Storage uses the same theme, control geometry and spacing as the inspectors. */
#app #tab-storage { padding: 6px; color: var(--cm-text, var(--text)); }
#app #tab-storage .settings-page-titlebar { min-height: 30px; padding: 3px 5px; margin-bottom: 5px; }
#app #tab-storage .storage-policy-section { gap: 6px; padding: 9px; margin: 0 0 7px; border: 1px solid var(--cm-border, var(--border)); border-radius: var(--cm-control-radius, 6px); background: var(--cm-surface, var(--panel)); }
#app #tab-storage .storage-policy-section > strong {
  margin: -9px -9px 2px; padding: 6px 9px; border-bottom: 1px solid var(--cm-border, var(--border));
  background: var(--cm-surface-2, var(--panel-2)); color: var(--cm-text, var(--text));
  font-size: 12px; font-style: normal; font-weight: 650; border-radius: var(--cm-control-radius, 6px) var(--cm-control-radius, 6px) 0 0;
}
#app #tab-storage label { gap: 4px; font-size: 12px; }
#app #tab-storage .storage-field { grid-template-columns: minmax(100px, 1fr) minmax(90px, 1fr); align-items: center; }
#app #tab-storage .storage-toggle { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 34px; align-items: center; gap: 8px; min-height: 27px; cursor: pointer; }
#app #tab-storage .storage-toggle > span { margin: 0; }
#app #tab-storage .storage-toggle > input { position: absolute; right: 0; top: 50%; transform: translateY(-50%); z-index: 1; width: 34px; height: 22px; margin: 0; opacity: 0; cursor: pointer; }
#app #tab-storage .storage-toggle-track { position: relative; width: 34px; height: 20px; border: 1px solid var(--cm-border, var(--border)); border-radius: 999px; background: var(--cm-surface-2, var(--panel-2)); transition: background .15s, border-color .15s; }
#app #tab-storage .storage-toggle-track::before { content: ''; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--cm-muted, var(--muted)); transition: transform .15s, background .15s; }
#app #tab-storage .storage-toggle input:checked + .storage-toggle-track { background: var(--cm-accent, var(--accent)); border-color: var(--cm-accent, var(--accent)); }
#app #tab-storage .storage-toggle input:checked + .storage-toggle-track::before { transform: translateX(14px); background: #fff; }
#app #tab-storage .storage-toggle input:focus-visible + .storage-toggle-track { outline: 2px solid var(--cm-accent, var(--accent)); outline-offset: 2px; }
#app #tab-storage .storage-toggle:has(input:disabled) { color: var(--cm-muted, var(--muted)); cursor: default; }
#app #tab-storage .storage-toggle input:disabled { cursor: default; }
#app #tab-storage .storage-toggle input:disabled + .storage-toggle-track { cursor: default; opacity: .5; }
#app #tab-storage input[type=number], #app #tab-storage select { height: 27px; min-height: 27px; padding: 3px 6px; font-size: 12px; color: var(--cm-text, var(--text)); background: var(--cm-surface, var(--panel)); border: 1px solid var(--cm-border, var(--border)); border-radius: var(--cm-control-radius, 5px); }
#app #tab-storage .storage-location-row { display: flex; align-items: end; gap: 6px; min-width: 0; }
#app #tab-storage .storage-location-row label { flex: 1; min-width: 0; }
#app #tab-storage label > output { padding: 5px 7px; white-space: normal; overflow: visible; overflow-wrap: anywhere; text-overflow: clip; color: var(--cm-text, var(--text)); background: var(--cm-surface-2, var(--panel-2)); border: 1px solid var(--cm-border, var(--border)); border-radius: var(--cm-control-radius, 5px); user-select: text; }
#app #tab-storage button { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 28px; max-width: 100%; padding: 4px 9px; border: 1px solid var(--cm-border, var(--border)); border-radius: var(--cm-control-radius, 5px); background: var(--cm-surface-2, var(--panel-2)); color: var(--cm-text, var(--text)); font: inherit; font-size: 12px; line-height: 1.3; box-shadow: none; transition: background .15s, border-color .15s; }
#app #tab-storage button:hover:not(:disabled) { background: var(--cm-accent-soft, var(--accent-soft)); border-color: var(--cm-accent, var(--accent)); }
#app #tab-storage button:focus-visible, #app #tab-storage :is(select,input[type=number]):focus-visible { outline: 2px solid var(--cm-accent, var(--accent)); outline-offset: 2px; }
#app #tab-storage button:disabled { opacity: .5; cursor: default; }
#app #tab-storage .storage-refresh-btn { padding: 4px; min-height: 27px; }
#app #tab-storage output { font-size: 11px; line-height: 1.45; overflow-wrap: anywhere; }
#app #tab-storage output:empty, #app #tab-storage [data-storage-result]:empty { display: none; }
#app #tab-storage progress { height: 5px; accent-color: var(--cm-accent, var(--accent)); }
#app #tab-storage .storage-hover-help {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
@media (prefers-reduced-motion: reduce) {
  #app #tab-storage :is(button, .storage-toggle-track), #app #tab-storage .storage-toggle-track::before { transition: none; }
}
/* Tree-only formatting shares the label/control columns of the surrounding settings. */
body #app #workspaceDocumentArea .workspace-pinned-actions {
  position: sticky !important; right: 0 !important; z-index: 12;
  display: flex !important; align-items: center; flex: 0 0 auto !important;
  margin-left: auto !important; padding: 0 4px; gap: 3px;
  background: var(--panel-alt, #f8fafc);
}
body #app #workspaceDocumentArea [data-workspace-actions] {
  display: inline-flex; align-items: center; gap: 3px; flex: 0 0 auto;
}
body #app :is(#metadataView, #clustersView) .data-toolbar-group {
  display: inline-flex; align-items: center; flex: 0 0 auto; gap: 3px;
  padding: 0 6px; border-inline-start: 1px solid var(--border, #dce3ed);
}
body #app :is(#metadataView, #clustersView) .data-toolbar-group:first-child {
  border-inline-start: 0; padding-inline-start: 0;
}
body #app #workspaceDocumentArea .analysis-actionbar-pinned {
  gap: 6px;
}
body #app #workspaceDocumentArea .analysis-actionbar-pinned > [data-workspace-actions] {
  margin-left: 0 !important; padding: 0;
}
body #app #workspaceDocumentArea [data-workspace-actions] :is(.tab-window-btn, [data-workspace-export]) {
  display: inline-grid !important; place-items: center;
  width: 27px !important; min-width: 27px !important; height: 27px !important;
  padding: 3px !important; border: 0 !important; border-radius: 4px;
  background: transparent; color: var(--muted, #526580); box-shadow: none !important;
}
body #app #workspaceDocumentArea [data-workspace-actions] :is(.tab-window-btn, [data-workspace-export]):hover {
  color: var(--accent, #315fc4); background: var(--hover, #eaf0fa);
}
body #app #workspaceDocumentArea [data-workspace-actions] .tab-window-controls { display: inline-flex; gap: 3px; }
body #app #workspaceDocumentArea [data-workspace-export] .save-chevron { display: none; }
body #app #workspaceDocumentArea .snapshot-workspace-actions .snapshot-export-menu > summary {
  display: inline-grid; place-items: center; list-style: none; cursor: pointer;
  width: 27px; height: 27px; padding: 3px; box-sizing: border-box; border: 0;
}
body #app #workspaceDocumentArea .snapshot-workspace-actions .snapshot-export-menu > summary::-webkit-details-marker { display: none; }
body #app #workspaceDocumentArea .analysis-save-menu[data-workspace-export-only] [hidden] { display: none !important; }
body #app #tab-appearance .studio-dependent-settings[hidden] { display: none !important; }
/* Legend field settings grow with their contents; the Settings panel owns scrolling. */
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings .metadata-field-legend > div {
  max-height: none !important; overflow: visible !important;
}
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings .tree-font-format-row {
  display: grid !important; grid-template-columns: minmax(0, var(--settings-label-column, 42%)) minmax(0, 1fr) !important;
  align-items: center; gap: 7px !important; grid-column: 1 / -1;
  box-sizing: border-box; width: 100%; min-width: 0; min-height: 28px; margin: 0 !important; padding: 1px 0 !important;
  background: transparent !important;
}
body #app #tab-appearance .tree-font-format-controls {
  display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.5fr) !important; align-items: center; gap: 3px;
  width: 100%; min-width: 0;
}
body #app #tab-appearance .tree-font-format-caption {
  min-width: 0; overflow-wrap: anywhere;
  text-align: left; font-size: var(--fi-font, 12px); line-height: 1.35;
}
/* Outrank the generic settings label grid, including metadata field rows. */
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings label:is(.tree-font-format-source, .tree-setting-button-source) { display: none !important; }
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings .settings-inline-grid:has(> :is(.tree-font-format-source, .tree-setting-button-source)):not(:has(> :not(.tree-font-format-source, .tree-setting-button-source, [hidden], .is-layout-hidden, .tree-settings-context-hidden))) { display: none !important; }
body #app #tab-appearance .tree-font-button {
  display: inline-grid; place-items: center; flex: 0 0 26px;
  min-width: 26px; max-width: 26px; width: 26px; height: 25px; min-height: 25px;
  padding: 0; border: 1px solid var(--border, #ccd8e8); border-radius: 4px;
  background: var(--panel, white); color: var(--text, #334155); font-size: 12px; line-height: 1;
}
body #app #tab-appearance .tree-font-bold { font-weight: 700; }
body #app #tab-appearance .tree-font-italic { font-family: Georgia, serif; font-style: italic; }
body #app #tab-appearance .tree-font-button[aria-pressed=true] {
  background: #e7efff; border-color: #7d9fde; color: #2454b8;
}
body #app #tab-appearance .tree-font-button[aria-pressed=mixed] {
  background: repeating-linear-gradient(135deg, #e7efff 0 4px, transparent 4px 8px);
}
body #app #tab-appearance .tree-font-format-controls > .tree-font-color {
  flex: 0 0 26px; width: 26px !important; min-width: 26px !important; max-width: 26px !important;
  height: 25px; min-height: 25px; padding: 0; margin: 0; border-radius: 4px; cursor: pointer;
}
body #app #tab-appearance .tree-font-color.is-mixed { outline: 1px dashed #7d9fde; outline-offset: 1px; }
body #app #tab-appearance .tree-font-button.tree-font-size {
  flex-basis: auto; width: auto; min-width: 49px; max-width: 73px; padding: 0 5px; white-space: nowrap; font-size: 11px;
}
body #app #tab-appearance .tree-font-format-controls > :is(.tree-font-button, .tree-font-color) {
  box-sizing: border-box; width: 100% !important; min-width: 0 !important; max-width: none !important;
}
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings .tree-font-format-controls > .tree-font-button {
  padding: 3px !important; min-height: 26px !important; height: 26px !important; white-space: nowrap !important;
}
body #app #tab-appearance .tree-font-button:focus-visible { outline: 2px solid #4275c5; outline-offset: 1px; }
body #app #tab-appearance .tree-font-button:disabled, body #app #tab-appearance .tree-font-color:disabled { opacity: .5; cursor: default; }
body #app #tab-appearance .tree-font-size-editor {
  position: fixed; inset: auto; z-index: 32000; width: 210px; max-width: calc(100vw - 12px);
  margin: 0; padding: 8px; border: 1px solid var(--border, #ccd8e8); border-radius: 7px;
  background: var(--panel, white); color: var(--text, #334155); box-shadow: 0 8px 26px #1c2b422e;
}
body #app #tab-appearance .tree-font-size-editor[hidden] { display: none !important; }
body #app #tab-appearance .tree-font-editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; }
body #app #tab-appearance .tree-font-editor-head strong { font-size: 12px; }
body #app #tab-appearance .tree-font-editor-head button { border: 0; background: transparent; }
body #app #tab-appearance .tree-font-size-editor label { display: grid; grid-template-columns: 1fr 90px; align-items: center; gap: 7px; margin: 5px 0; font-size: 12px; }
body #app #tab-appearance .tree-font-size-editor :is(input,select) { width: 90px; min-width: 0; height: 26px; min-height: 26px; padding: 2px 4px; font-size: 12px; }
body #app #tab-appearance .tree-font-size-editor > button { width: auto; min-width: 62px; max-width: none; padding: 0 7px; margin-top: 3px; }
/* Numeric popovers and segmented choices keep the same input-column width. */
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings .tree-setting-button-row {
  display: grid !important; grid-template-columns: minmax(0, var(--settings-label-column, 42%)) minmax(0, 1fr) !important;
  align-items: center; gap: 7px !important; grid-column: 1 / -1;
  box-sizing: border-box; width: 100%; min-width: 0; min-height: 28px; margin: 0 !important; padding: 1px 0 !important;
  background: transparent !important;
}
body #app #tab-appearance .tree-setting-button-caption { min-width: 0; overflow-wrap: anywhere; font-size: var(--fi-font, 12px); line-height: 1.35; }
body #app #tab-appearance .tree-setting-button-controls { display: flex !important; flex-wrap: nowrap !important; align-items: center; gap: 3px; width: 100%; min-width: 0; }
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings .tree-setting-button-controls > .tree-setting-button {
  flex: 1 1 0; width: 100% !important; min-width: 0 !important; max-width: none !important; padding: 3px !important;
  min-height: 26px !important; height: 26px !important;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap !important; font-size: 11px !important;
}
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings :is(.tree-font-format-row, .tree-setting-button-row, .tree-font-button)[hidden] { display: none !important; }
body #app #tab-appearance .settings-inline-grid:has(> :is(.tree-font-format-row, .tree-setting-button-row)) {
  display: grid !important; grid-template-columns: minmax(0, 1fr) !important;
}
body #app #tab-appearance :is(.tree-font-format-caption, .tree-setting-button-caption) { grid-column: 1; grid-row: 1; }
body #app #tab-appearance :is(.tree-font-format-controls, .tree-setting-button-controls) { grid-column: 2; grid-row: 1; }
@container settings-pane (max-width:260px) {
  body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings :is(.tree-font-format-row, .tree-setting-button-row) {
    grid-template-columns: minmax(0, 38%) minmax(0, 1fr) !important;
  }
}
body #app #tab-appearance .tree-setting-number-editor > input { box-sizing: border-box; width: 100%; min-width: 0; max-width: 100%; }
/* Preserve the existing inline controls in the tree's individual-label editor. */
body .tree-node-editor-dialog .label-color-format { display: inline-flex; align-items: center; gap: 4px; }
body .tree-node-editor-dialog .text-color-format-row { display: flex; align-items: center; gap: 5px; }
body .tree-node-editor-dialog .text-color-format-row > span:first-child { flex: 1; }
body .tree-node-editor-dialog .text-color-format-row input[data-color-control] { width: 42px; flex: 0 0 42px; }

/* Storage refresh reports progress beside its icon, including on slow native drives. */
#app #tab-storage .storage-refresh-status { flex: 0 1 auto; min-width: 0; max-width: 48%; font-size: 10px; color: var(--cm-muted, var(--muted)); overflow-wrap: anywhere; }
#app #tab-storage .storage-refresh-status[data-state=error] { color: var(--danger, #b42318); }
#app #tab-storage .storage-refresh-btn.is-refreshing .ui-icon { animation: storage-refresh-spin .8s linear infinite; }
@keyframes storage-refresh-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #app #tab-storage .storage-refresh-btn.is-refreshing .ui-icon { animation: none; } }

/* Quiet selected toggles; metadata tabs retain their own white active surface. */
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings
  button:is([aria-pressed='true'], .tree-font-button[aria-expanded='true']) {
  background: #eaf1f8 !important;
  border-color: #a9bdd2 !important;
  color: #345575 !important;
  box-shadow: none !important;
  font-weight: 600 !important;
}
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings
  button[aria-pressed='mixed'] {
  background: repeating-linear-gradient(135deg, #eef3f8 0 5px, #f8fafc 5px 10px) !important;
  border-color: #b8c7d8 !important;
  color: #52677d !important;
  box-shadow: none !important;
}
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings
  button:is([aria-pressed='true'], [aria-selected='true'], [aria-pressed='mixed'], .tree-font-button[aria-expanded='true']):focus-visible {
  outline: 2px solid var(--fi-accent, #375dfb) !important;
  outline-offset: 2px !important;
}
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings .tree-font-bold {
  font-weight: 750 !important;
}
body #app #tab-appearance.tree-settings.control-page.figure-settings.unified-settings
  .tree-font-color[aria-expanded='true'] {
  outline: 2px solid var(--fi-accent, #375dfb) !important;
  outline-offset: 2px !important;
}
