/* Theme Editor v2 — central designer workspace.
 *
 * The editor stays deliberately inside the existing Studio token system. It
 * uses flex/table layout so the same bundle paints consistently in Chromium
 * and ForgeUI's embedded surface, and all scroll ownership is explicit to
 * avoid the historical full-window horizontal scrollbar.
 */

.theme-mode {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-0, #111318);
    color: var(--text-0, #e5e7eb);
    font: 11px Inter, sans-serif;
}

.theme-mode-topbar {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    min-height: 42px;
    height: 42px;
    padding: 0 10px;
    flex: 0 0 auto;
    border-bottom: 1px solid rgba(65, 71, 85, .38);
    background: var(--bg-1, #16191f);
    overflow: hidden;
}
.theme-mode-topbar .theme-top-spacer { flex: 1 1 auto; min-width: 8px; }
.theme-mode-title {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    color: var(--text-0);
    font-weight: 800;
    letter-spacing: .02em;
}
.theme-mode-title .ms-icon { color: var(--primary); font-size: 16px; }
.theme-select-field {
    width: 156px;
    min-width: 112px;
    height: 26px;
    flex: 0 1 156px;
}
.theme-select { width: 100%; min-width: 0; height: 26px; }
.theme-variant-strip {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    max-width: 38%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.theme-variant-strip::-webkit-scrollbar { width: 0; height: 0; }
.theme-variant-chip {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 9px;
    flex: 0 0 auto;
    border: 1px solid rgba(65, 71, 85, .55);
    border-radius: 12px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}
.theme-variant-chip.active {
    border-color: var(--primary);
    color: var(--text-0);
    background: rgba(33, 147, 251, .14);
}
.theme-variant-chip.applied::after {
    width: 5px;
    height: 5px;
    margin-left: 6px;
    flex: 0 0 5px;
    border-radius: 50%;
    background: var(--primary);
    content: "";
}
.theme-impact {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 8px;
    flex: 0 0 auto;
    border-radius: 4px;
    color: var(--text-1);
    background: rgba(255, 255, 255, .035);
}
.theme-impact .ms-icon { font-size: 14px; color: var(--primary); }

.theme-managed-boundary-note {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    min-width: 0;
    padding: 5px 10px;
    flex: 0 0 auto;
    border-bottom: 1px solid rgba(65, 71, 85, .28);
    background: rgba(33, 147, 251, .045);
    color: var(--text-2);
    font-size: 9px;
    line-height: 1.35;
}
.theme-managed-boundary-note .ms-icon {
    margin-top: 1px;
    flex: 0 0 auto;
    color: var(--primary);
    font-size: 13px;
}
.theme-managed-boundary-note > span:last-child { min-width: 0; }

.theme-mode-workspace {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
.theme-mode-rail {
    display: flex;
    flex-direction: column;
    width: 172px;
    min-width: 142px;
    max-width: 190px;
    flex: 0 0 172px;
    padding: 8px 6px;
    border-right: 1px solid rgba(65, 71, 85, .34);
    background: var(--bg-1, #16191f);
    overflow-y: auto;
    overflow-x: hidden;
}
.theme-rail-label {
    padding: 7px 8px 4px;
    color: var(--text-2);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.theme-rail-divider {
    height: 1px;
    margin: 7px 5px;
    background: rgba(65, 71, 85, .34);
}
.theme-rail-button {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    min-height: 30px;
    padding: 5px 8px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--text-1);
    text-align: left;
    cursor: pointer;
}
.theme-rail-button:hover { background: rgba(255, 255, 255, .045); }
.theme-rail-button.active {
    background: rgba(33, 147, 251, .16);
    color: var(--text-0);
}
.theme-rail-button .ms-icon { font-size: 15px; color: var(--text-2); }
.theme-rail-button.active .ms-icon { color: var(--primary); }
.theme-rail-button .theme-rail-count {
    margin-left: auto;
    min-width: 18px;
    padding: 1px 5px;
    border-radius: 9px;
    background: rgba(255, 255, 255, .055);
    color: var(--text-2);
    font-size: 9px;
    text-align: center;
}
/* Inventory counts are neutral; a pending divergence is work waiting. Same
   tint as the inline ≈ marker so both read as one signal. */
.theme-rail-button .theme-rail-count-warn {
    background: rgba(241, 199, 91, .16);
    color: #f1c75b;
    font-weight: 700;
}

.theme-mode-main {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-0, #111318);
}
.theme-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    padding: 7px 12px;
    flex: 0 0 auto;
    border-bottom: 1px solid rgba(65, 71, 85, .28);
}
.theme-section-heading {
    min-width: 110px;
    flex: 0 0 auto;
    font-size: 13px;
    font-weight: 800;
    color: var(--text-0);
}
.theme-token-search {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 140px;
    max-width: 320px;
    height: 27px;
    padding: 0 7px;
    flex: 1 1 240px;
    border: 1px solid rgba(65, 71, 85, .45);
    border-radius: 5px;
    background: var(--bg-2, #1d2027);
}
.theme-token-search .ms-icon { font-size: 14px; color: var(--text-2); }
.theme-token-search input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-0);
}
.theme-token-table-scroll {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}
.theme-token-table {
    width: 100%;
    min-width: 520px;
    table-layout: fixed;
    border-collapse: collapse;
}
.theme-token-table th {
    position: sticky;
    top: 0;
    z-index: 3;
    height: 30px;
    padding: 0 8px;
    border-bottom: 1px solid rgba(65, 71, 85, .42);
    border-right: 1px solid rgba(65, 71, 85, .22);
    background: var(--bg-1, #16191f);
    color: var(--text-2);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .05em;
    text-align: left;
    text-transform: uppercase;
}
.theme-token-table th:first-child { width: 188px; }
.theme-token-table th:last-child { width: 52px; text-align: center; }
.theme-token-table td {
    height: 42px;
    padding: 5px 8px;
    border-bottom: 1px solid rgba(65, 71, 85, .22);
    border-right: 1px solid rgba(65, 71, 85, .14);
    vertical-align: middle;
    background: rgba(255, 255, 255, .006);
}
.theme-token-table tr:hover td { background: rgba(255, 255, 255, .025); }
.theme-token-table .theme-token-group-row td {
    height: 28px;
    padding: 7px 10px 4px;
    border-right: 0;
    background: var(--bg-1, #16191f);
}
.theme-token-table .theme-token-group-row:hover td { background: var(--bg-1, #16191f); }
.theme-token-group-label {
    color: var(--text-2);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.theme-token-name-cell {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    cursor: pointer;
}
.theme-token-name {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    color: var(--text-0);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-token-usage {
    min-width: 20px;
    padding: 1px 5px;
    flex: 0 0 auto;
    border-radius: 9px;
    background: rgba(33, 147, 251, .12);
    color: var(--text-1);
    font-size: 9px;
    text-align: center;
}
.theme-token-swatch {
    position: relative;
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 4px;
    background: repeating-conic-gradient(#3d434f 0 25%, #23272f 0 50%) 0 / 8px 8px;
}
.theme-token-swatch > span { position: absolute; inset: 0; }
.theme-token-cell {
    position: relative;
    min-width: 0;
    outline: 0;
}
.theme-token-cell:focus {
    box-shadow: inset 0 0 0 2px var(--primary, #2193fb);
}
.theme-token-cell > .prop-input,
.theme-token-cell > .prop-enum-select-field,
.theme-token-cell > .prop-unit-select-field { min-width: 0; }
.theme-token-cell.inherited { opacity: .58; }
.theme-token-cell.inherited::after {
    content: attr(data-inherited-label);
    position: absolute;
    right: 8px;
    bottom: -1px;
    color: var(--text-2);
    font-size: 8px;
    pointer-events: none;
}
.theme-token-cell.inherited .prop-input,
.theme-token-cell.inherited .prop-enum-select-field,
.theme-token-cell.inherited .prop-unit-select-field {
    border-style: dashed;
}
.theme-clear-override {
    position: absolute;
    right: 3px;
    top: 3px;
    width: 16px;
    height: 16px;
    padding: 0;
    border: 0;
    border-radius: 3px;
    background: rgba(0, 0, 0, .32);
    color: var(--text-2);
    cursor: pointer;
    z-index: 2;
}
.theme-clear-override:hover { color: var(--danger); }
.theme-token-actions { text-align: center; }

.theme-mode-inspector {
    display: flex;
    flex-direction: column;
    width: 292px;
    min-width: 240px;
    max-width: 340px;
    flex: 0 0 292px;
    border-left: 1px solid rgba(65, 71, 85, .34);
    background: var(--bg-1, #16191f);
    overflow: hidden;
}
.theme-inspector-header {
    display: flex;
    align-items: center;
    min-height: 38px;
    padding: 0 10px;
    flex: 0 0 auto;
    border-bottom: 1px solid rgba(65, 71, 85, .34);
    font-size: 11px;
    font-weight: 800;
}
.theme-inspector-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 9px;
    overflow-y: auto;
    overflow-x: hidden;
}
.theme-inspector-block {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(65, 71, 85, .28);
}
.theme-refactor-scope {
    display: flex;
    margin: 8px 0 10px;
    padding: 8px;
    flex-direction: column;
    gap: 6px;
    border: 1px solid rgba(65, 71, 85, .38);
    border-radius: 5px;
    background: rgba(255, 255, 255, .018);
}
.theme-refactor-scope-current {
    color: var(--text-0);
    font-size: 10px;
    font-weight: 700;
}
.theme-refactor-toggle {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    min-width: 0;
    color: var(--text-1);
    font-size: 10px;
    line-height: 1.35;
    cursor: pointer;
}
.theme-refactor-toggle input {
    margin: 1px 0 0;
    flex: 0 0 auto;
    accent-color: var(--primary, #2193fb);
}
.theme-scope-loading { color: var(--primary, #2193fb); }
.theme-group-combobox {
    position: relative;
    display: flex;
    min-width: 0;
}
.theme-group-combobox > .prop-input {
    min-width: 0;
    flex: 1 1 auto;
    border-radius: 4px 0 0 4px;
}
.theme-group-toggle {
    width: 28px;
    min-width: 28px;
    border: 1px solid var(--border, #343a46);
    border-left: 0;
    border-radius: 0 4px 4px 0;
    background: var(--bg-2, #202833);
    color: var(--text-1);
}
.theme-group-menu {
    position: absolute;
    top: calc(100% + 3px);
    left: 0;
    right: 0;
    z-index: 40;
    display: flex;
    padding: 4px;
    flex-direction: column;
    gap: 2px;
    border: 1px solid var(--border, #343a46);
    border-radius: 5px;
    background: var(--bg-1, #16191f);
    box-shadow: 0 8px 22px rgba(0, 0, 0, .42);
}
.theme-group-menu[hidden] { display: none; }
.theme-group-option {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 27px;
    padding: 4px 7px;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: var(--text-1);
    text-align: left;
}
.theme-group-option:hover,
.theme-group-option.active,
.theme-group-option[aria-selected="true"] { background: rgba(33, 147, 251, .18); }
.theme-group-custom { border-top: 1px solid rgba(65, 71, 85, .38); }
.theme-field-label {
    display: block;
    margin: 7px 0 4px;
    color: var(--text-2);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
}
.theme-inspector-body textarea.prop-input {
    min-height: 56px;
    height: auto;
    padding-top: 6px;
    resize: vertical;
}
.theme-usage-list { display: flex; flex-direction: column; gap: 3px; }
.theme-usage-item {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 4px 6px;
    border: 1px solid rgba(65, 71, 85, .25);
    border-radius: 4px;
    background: rgba(255, 255, 255, .018);
    color: var(--text-1);
    cursor: pointer;
    text-align: left;
}
.theme-usage-item:hover { border-color: rgba(33, 147, 251, .55); }
.theme-usage-item .ms-icon { font-size: 13px; color: var(--text-2); }
.theme-usage-item-label {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-danger-zone {
    padding: 8px;
    border: 1px solid rgba(255, 92, 108, .30);
    border-radius: 5px;
    background: rgba(255, 92, 108, .06);
}
.theme-danger-zone .small-primary-btn { background: var(--danger, #ff5c6c); }
.theme-delete-explanation {
    margin: 6px 0;
    color: var(--text-2);
    font-size: 10px;
    line-height: 1.4;
}

.theme-preview-dock {
    display: flex;
    min-height: 132px;
    height: 154px;
    flex: 0 0 154px;
    flex-direction: column;
    border-top: 1px solid rgba(65, 71, 85, .38);
    background: var(--bg-1, #16191f);
}
.theme-preview-dock.collapsed {
    min-height: 30px;
    height: 30px;
    flex: 0 0 30px;
    flex-basis: 30px;
    overflow: hidden;
}
.theme-preview-header {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 30px;
    padding: 0 9px;
    flex: 0 0 auto;
    border-bottom: 1px solid rgba(65, 71, 85, .25);
    color: var(--text-2);
}
.theme-preview-header strong { color: var(--text-0); }
.theme-preview-screen { width: 180px; height: 23px; }
.theme-preview-header select { width: 100%; height: 23px; }
.theme-preview-list {
    display: flex;
    align-items: stretch;
    gap: 8px;
    min-height: 0;
    padding: 7px 9px;
    flex: 1 1 auto;
    overflow-x: auto;
    overflow-y: hidden;
}
.theme-preview-card {
    position: relative;
    display: flex;
    width: 184px;
    min-width: 184px;
    flex: 0 0 184px;
    overflow: hidden;
    border: 1px solid rgba(65, 71, 85, .52);
    border-radius: 5px;
    background: #0c0e12;
    cursor: pointer;
}
.theme-preview-card.selected {
    outline: 1px solid rgba(33, 147, 251, .72);
    outline-offset: 2px;
}
.theme-preview-card.active {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px rgba(33, 147, 251, .42);
}
.theme-preview-card iframe {
    position: absolute;
    left: 50%;
    top: 50%;
    border: 0;
    pointer-events: none;
    transform-origin: center;
}
.theme-preview-label {
    position: absolute;
    left: 4px;
    bottom: 4px;
    z-index: 2;
    padding: 2px 5px;
    border-radius: 3px;
    background: rgba(0, 0, 0, .72);
    color: white;
    font-size: 9px;
}
.theme-preview-apply { flex: 0 0 auto; white-space: nowrap; }

.theme-empty {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
}
.theme-empty .ms-icon { margin-bottom: 10px; color: var(--primary); font-size: 34px; }
.theme-empty h2 { margin: 0 0 7px; color: var(--text-0); font-size: 18px; }
.theme-empty p { max-width: 460px; margin: 0 0 16px; color: var(--text-2); line-height: 1.5; }
.theme-create-card {
    display: flex;
    width: 92%;
    max-width: 520px;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    border: 1px solid rgba(65, 71, 85, .42);
    border-radius: 8px;
    background: var(--bg-1);
    text-align: left;
}
.theme-create-row { display: flex; align-items: center; gap: 8px; }
.theme-create-row .prop-input { flex: 1 1 160px; min-width: 96px; }
.theme-create-row .small-primary-btn { flex: 0 0 auto; min-width: max-content; align-items: center; justify-content: center; white-space: nowrap; }
.theme-create-row .small-primary-btn > .ms-icon { flex: 0 0 auto; line-height: 1; }
.theme-starter-toggle { display: flex; align-items: center; gap: 7px; color: var(--text-1); }

.theme-card-list,
.theme-asset-grid,
.theme-divergence-list,
.theme-document-list {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    padding: 12px;
    gap: 8px;
    flex-wrap: wrap;
    align-content: flex-start;
    overflow: auto;
}
.theme-component-card,
.theme-divergence-card,
.theme-document-card {
    display: flex;
    min-width: 220px;
    max-width: 360px;
    min-height: 70px;
    padding: 9px;
    flex: 1 1 260px;
    flex-direction: column;
    gap: 6px;
    border: 1px solid rgba(65, 71, 85, .36);
    border-radius: 6px;
    background: var(--bg-1);
}
.theme-component-card.active { border-color: var(--primary); }
.theme-component-pager {
    display: flex;
    flex: 1 0 100%;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 34px;
    padding: 4px 8px;
}
.theme-divergence-usage {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 5px;
    border-top: 1px solid rgba(65, 71, 85, .24);
}
.theme-divergence-usage > .theme-card-meta {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-divergence-bulk { align-self: flex-end; }
.theme-component-card-open {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 28px;
    padding: 0;
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
}
.theme-component-card-open .theme-card-title {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-component-card-open .theme-card-meta { flex: 0 0 auto; }
.theme-component-card-open:focus-visible {
    outline: 1px solid var(--primary);
    outline-offset: 2px;
}
.theme-card-title { color: var(--text-0); font-weight: 800; }
.theme-card-meta { color: var(--text-2); font-size: 9px; }
.theme-component-preview-slot {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 104px;
    min-height: 104px;
    flex: 0 0 104px;
    overflow: hidden;
    border: 1px solid rgba(65, 71, 85, .35);
    border-radius: 6px;
    background: #101318;
}
.theme-component-preview-slot.previewing { background: #fff; }
.theme-component-preview-placeholder {
    padding: 8px;
    color: var(--text-2);
    font-size: 9px;
    text-align: center;
}
.theme-component-preview-snapshot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    pointer-events: none;
}
.theme-component-preview-snapshot > * {
    max-width: calc(100% - 12px) !important;
    max-height: calc(100% - 12px) !important;
}
.theme-component-preview-snapshot:not(.ready),
.theme-component-preview-slot.previewing .theme-component-preview-placeholder,
.theme-component-preview-snapshot.ready + .theme-component-preview-placeholder {
    display: none;
}
.theme-component-preview-slot.previewing .theme-component-preview-snapshot {
    display: none !important;
}
.theme-component-preview-slot iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}
.theme-component-preview-renderer {
    position: fixed;
    left: -10000px;
    top: 0;
    z-index: -1;
    width: 720px;
    height: 400px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    contain: strict;
}
.theme-component-preview-renderer iframe {
    display: block;
    width: 720px;
    height: 400px;
    border: 0;
}
.theme-settings-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 10px 12px 0;
    padding: 9px 10px;
    flex: 0 0 auto;
    border: 1px solid rgba(65, 71, 85, .36);
    border-radius: 6px;
    background: var(--bg-1);
}
.theme-settings-copy {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 3px;
}
.theme-settings-panel > .chip { flex: 0 0 auto; }
.theme-asset-card {
    display: flex;
    width: 126px;
    height: 112px;
    padding: 6px;
    flex: 0 0 126px;
    flex-direction: column;
    gap: 5px;
    border: 1px solid rgba(65, 71, 85, .36);
    border-radius: 6px;
    background: var(--bg-1);
    cursor: pointer;
}
.theme-asset-card:hover { border-color: var(--primary); }
.theme-asset-card img {
    width: 100%;
    min-height: 0;
    flex: 1 1 auto;
    object-fit: contain;
    background: repeating-conic-gradient(#343943 0 25%, #22262d 0 50%) 0 / 10px 10px;
}
.theme-asset-card span {
    overflow: hidden;
    color: var(--text-1);
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-asset-load-more { flex: 1 0 100%; justify-content: center; }
.theme-document-screens {
    display: flex;
    max-height: 220px;
    min-height: 92px;
    flex: 0 1 220px;
    flex-direction: column;
    border-top: 1px solid rgba(65, 71, 85, .34);
}
.theme-document-screen-list {
    display: grid;
    min-height: 0;
    padding: 8px 12px 12px;
    gap: 5px;
    overflow-y: auto;
}
.theme-document-screen {
    display: flex;
    min-width: 0;
    min-height: 34px;
    padding: 5px 7px;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(65, 71, 85, .3);
    border-radius: 5px;
    background: var(--bg-1);
    color: var(--text-1);
    cursor: pointer;
    text-align: left;
}
.theme-document-screen:hover,
.theme-document-screen:focus-visible { border-color: var(--primary); }
.theme-document-screen[aria-current="page"] { background: rgba(33, 147, 251, .08); }
.theme-document-screen-copy {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: column;
}
.theme-document-screen-copy > strong,
.theme-document-screen-copy > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-screen-assignment {
    max-width: 132px;
    padding: 2px 6px;
    flex: 0 1 auto;
    overflow: hidden;
    border: 1px solid rgba(65, 71, 85, .38);
    border-radius: 999px;
    color: var(--text-2);
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-screen-assignment.active { border-color: rgba(33, 147, 251, .65); color: var(--primary); }
.theme-scale-form {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(65, 71, 85, .25);
}
.theme-scale-copy {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
}
.theme-scale-copy > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.theme-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 10030;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 24px;
    background: rgba(4, 6, 10, .76);
}
.theme-spacing-dialog {
    display: flex;
    box-sizing: border-box;
    width: min(620px, calc(100vw - 32px));
    max-height: min(720px, calc(100vh - 32px));
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(91, 101, 120, .62);
    border-radius: 8px;
    background: var(--bg-1, #171a20);
    color: var(--text-0);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
}
.theme-spacing-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 42px;
    padding: 0 12px 0 16px;
    flex: 0 0 auto;
    border-bottom: 1px solid rgba(65, 71, 85, .38);
}
.theme-spacing-dialog-header h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
}
.theme-spacing-dialog-help {
    margin: 0;
    padding: 10px 16px 2px;
    color: var(--text-2);
    font-size: 10px;
    line-height: 1.45;
}
.theme-spacing-dialog-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 10px 16px;
}
.theme-spacing-dialog-field,
.theme-spacing-dialog-token-field {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 4px;
    color: var(--text-2);
    font-size: 9px;
}
.theme-spacing-dialog-field .prop-input,
.theme-spacing-dialog-token-field .prop-input { width: 100%; min-width: 0; }
.theme-spacing-dialog-preview-label {
    padding: 2px 16px 7px;
    color: var(--text-1);
    font-size: 10px;
    font-weight: 600;
}
.theme-spacing-dialog-preview {
    display: flex;
    min-height: 96px;
    padding: 0 16px;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 6px;
    overflow: auto;
}
.theme-spacing-dialog-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
    flex: 0 0 auto;
}
.theme-spacing-dialog-field .prop-input[aria-invalid="true"],
.theme-spacing-dialog-token-field .prop-input[aria-invalid="true"] {
    border-color: var(--danger, #ff5c6c);
}
.theme-spacing-dialog-status {
    min-height: 15px;
    padding: 7px 16px 0;
    flex: 0 0 auto;
    color: var(--danger, #ff7785);
    font-size: 9px;
}
.theme-spacing-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
    padding: 10px 16px 14px;
    flex: 0 0 auto;
}
@media (max-width: 520px) {
    .theme-dialog-overlay { padding: 8px; }
    .theme-spacing-dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
    .theme-spacing-dialog-controls,
    .theme-spacing-dialog-row { grid-template-columns: minmax(0, 1fr); }
    .theme-preview-header > .theme-card-meta { display: none; }
}
.theme-suggestions {
    display: flex;
    gap: 4px;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.theme-suggestions::-webkit-scrollbar { width: 0; height: 0; }
.theme-suggestion { flex: 0 0 auto; }
.theme-token-virtual-row td {
    height: 0;
    padding: 0;
    border: 0;
    background: transparent;
}
.theme-token-virtual-pad { width: 1px; pointer-events: none; }

/* var(--token) references in ordinary Inspector / Styles fields. */
.prop-token-reference {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    height: 27px;
    padding: 0 4px 0 6px;
    flex: 1 1 auto;
    border: 1px solid rgba(65, 71, 85, .45);
    border-radius: 5px;
    background: var(--bg-2);
}
.prop-token-reference-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    padding: 0;
    flex: 1 1 auto;
    border: 0;
    background: transparent;
    color: var(--text-0);
    cursor: pointer;
}
.prop-token-reference-name {
    min-width: 0;
    overflow: hidden;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.prop-token-expression .prop-token-reference-name { color: var(--primary, #2193fb); }
.prop-token-reference-x,
.prop-token-menu-btn,
.prop-token-divergence {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 24px;
    padding: 0;
    flex: 0 0 22px;
    border: 1px solid rgba(65, 71, 85, .32);
    border-radius: 4px;
    background: var(--bg-3);
    color: var(--text-2);
    cursor: pointer;
}
.prop-token-menu-btn .ms-icon { font-size: 13px; }
.prop-token-divergence { color: #f1c75b; font-weight: 800; }
.prop-token-popup {
    position: fixed;
    z-index: 9850;
    display: flex;
    width: 230px;
    max-height: 280px;
    padding: 5px;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    border: 1px solid rgba(65, 71, 85, .62);
    border-radius: 6px;
    background: var(--bg-1, #17191f);
    box-shadow: 0 10px 34px rgba(0, 0, 0, .52);
}
.prop-token-popup button {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 28px;
    padding: 4px 7px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-1);
    cursor: pointer;
    text-align: left;
}
.prop-token-popup button:hover { background: rgba(33, 147, 251, .14); color: var(--text-0); }
.prop-token-popup .prop-token-popup-extract { border-top: 1px solid rgba(65, 71, 85, .32); color: var(--primary); }

.theme-token-name-popover {
    position: fixed;
    z-index: 10020;
    box-sizing: border-box;
    width: 258px;
    padding: 10px;
    border: 1px solid rgba(65, 71, 85, .68);
    border-radius: 7px;
    background: var(--bg-1, #17191f);
    box-shadow: 0 12px 36px rgba(0, 0, 0, .58);
}
.theme-token-name-title {
    margin-bottom: 9px;
    color: var(--text-0);
    font-size: 11px;
    font-weight: 800;
}
.theme-token-name-label {
    display: block;
    margin-bottom: 4px;
    color: var(--text-2);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
}
.theme-token-name-input { width: 100%; box-sizing: border-box; }
.theme-token-name-status {
    min-height: 15px;
    padding-top: 4px;
    color: #f1c75b;
    font-size: 9px;
    line-height: 1.35;
}
.theme-token-name-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 5px;
    margin-top: 7px;
}
.theme-token-name-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    height: 26px;
}

/* Narrow Studio windows retain all three work areas. The impact badge becomes
   compact first, then the inspector stacks below the rail/main row rather than
   disappearing while the user is editing a token. Runtime classes follow the
   real Theme dock width; media queries remain a browser fallback. */
.theme-mode.theme-width-narrow .theme-mode-inspector {
    width: 250px;
    flex-basis: 250px;
}
.theme-mode.theme-width-narrow .theme-mode-rail { width: 148px; flex-basis: 148px; }
.theme-mode.theme-width-narrow .theme-impact {
    display: inline-flex;
    min-width: 28px;
    max-width: 116px;
    padding-right: 5px;
    padding-left: 5px;
    flex: 0 1 116px;
}
.theme-mode.theme-width-narrow .theme-impact .ms-icon { flex: 0 0 auto; }
.theme-mode.theme-width-narrow .theme-impact span:last-child {
    min-width: 0;
    overflow: hidden;
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-mode.theme-width-compact .theme-mode-workspace {
    flex-flow: row wrap;
    align-content: stretch;
}
.theme-mode.theme-width-compact .theme-mode-rail {
    box-sizing: border-box;
    width: 112px;
    min-width: 112px;
    max-width: 112px;
    height: 62%;
    flex: 0 0 112px;
}
.theme-mode.theme-width-compact .theme-mode-main {
    box-sizing: border-box;
    width: calc(100% - 112px);
    height: 62%;
    flex: 1 1 0;
}
.theme-mode.theme-width-compact .theme-mode-inspector {
    box-sizing: border-box;
    display: flex;
    width: 100%;
    min-width: 0;
    max-width: none;
    min-height: 0;
    height: 38%;
    flex: 0 0 100%;
    border-top: 1px solid rgba(65, 71, 85, .34);
    border-left: 0;
}
.theme-mode.theme-width-compact .theme-impact { max-width: 82px; flex-basis: 82px; }

@media (max-width: 1080px) {
    .theme-mode-inspector { width: 250px; flex-basis: 250px; }
    .theme-mode-rail { width: 148px; flex-basis: 148px; }
    .theme-impact {
        display: inline-flex;
        min-width: 28px;
        max-width: 116px;
        padding-right: 5px;
        padding-left: 5px;
        flex: 0 1 116px;
    }
    .theme-impact .ms-icon { flex: 0 0 auto; }
    .theme-impact span:last-child {
        min-width: 0;
        overflow: hidden;
        font-size: 9px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}
@media (max-width: 860px) {
    .theme-mode-workspace {
        flex-flow: row wrap;
        align-content: stretch;
    }
    .theme-mode-rail {
        box-sizing: border-box;
        width: 112px;
        min-width: 112px;
        max-width: 112px;
        height: 62%;
        flex: 0 0 112px;
    }
    .theme-mode-main {
        box-sizing: border-box;
        width: calc(100% - 112px);
        height: 62%;
        flex: 1 1 0;
    }
    .theme-mode-inspector {
        box-sizing: border-box;
        display: flex;
        width: 100%;
        min-width: 0;
        max-width: none;
        min-height: 0;
        height: 38%;
        flex: 0 0 100%;
        border-top: 1px solid rgba(65, 71, 85, .34);
        border-left: 0;
    }
    .theme-impact { max-width: 82px; flex-basis: 82px; }
}

/* Container-width classes are authoritative inside docked editor hosts, where
 * viewport media queries see the whole native window rather than the Stage. */
.theme-mode.theme-width-narrow .theme-mode-topbar {
    gap: 4px;
    padding-inline: 7px;
}
.theme-mode.theme-width-narrow .theme-mode-title { max-width: 118px; overflow: hidden; }
.theme-mode.theme-width-narrow .theme-select-field { min-width: 96px; flex-basis: 118px; }
.theme-mode.theme-width-narrow .theme-variant-strip { max-width: none; flex: 1 1 120px; }
.theme-mode.theme-width-compact .theme-mode-topbar { min-height: 70px; height: auto; flex-wrap: wrap; align-content: center; overflow: hidden; }
.theme-mode.theme-width-compact .theme-mode-title { max-width: calc(100% - 126px); }
.theme-mode.theme-width-compact .theme-select-field { order: 4; width: 118px; flex: 0 1 118px; }
.theme-mode.theme-width-compact .theme-variant-strip { order: 5; flex: 1 1 calc(100% - 130px); max-width: calc(100% - 130px); }
.theme-mode.theme-width-compact .theme-impact { margin-left: auto; max-width: 82px; }
.theme-mode.theme-width-compact .theme-impact span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-mode.theme-width-compact .theme-top-spacer { display: none; }
.theme-mode.theme-width-compact .theme-mode-topbar > button { flex: 0 0 auto; }
@media (max-width: 520px) {
    .theme-mode-topbar { min-height: 70px; height: auto; flex-wrap: wrap; }
    .theme-mode-title { max-width: 104px; overflow: hidden; }
    .theme-impact span:last-child { display: none; }
}
