/* ============================================================
   GitHub-Inspired Design System — XML Editor
   ============================================================ */

/* ── CSS Custom Properties ─────────────────────────────────── */
:root {
    color-scheme: light;

    /* GitHub palette */
    --color-header-bg: #24292e;
    --color-header-text: #ffffff;
    --color-header-hover: #57606a;
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f6f8fa;
    --color-bg-tertiary: #eef1f5;
    --color-border: #d0d7de;
    --color-border-muted: #d8dee4;
    --color-text-primary: #1f2328;
    --color-text-secondary: #656d76;
    --color-text-muted: #8b949e;
    --color-link: #0969da;
    --color-accent-fg: #0969da;
    --color-success: #1a7f37;
    --color-success-bg: #dafbe1;
    --color-danger: #cf222e;
    --color-danger-bg: #ffebe9;
    --color-warning: #9a6700;
    --color-warning-bg: #fff8c5;
    --color-info-bg: #ddf4ff;

    /* Channel triplets for alpha tints: rgba(var(--rgb-accent), 0.28) */
    --rgb-accent: 9, 105, 218;
    --rgb-success: 26, 127, 55;
    --rgb-danger: 207, 34, 46;
    --rgb-warning: 154, 103, 0;

    /* Solid (emphasis) fills — white text sits on these */
    --color-accent-emphasis: #0969da;
    --color-accent-emphasis-hover: #0550ae;
    --color-success-emphasis: #1a7f37;
    --color-success-emphasis-hover: #188636;
    --color-danger-emphasis: #cf222e;
    --color-danger-emphasis-hover: #a40e26;

    /* Scrims / backdrops */
    --color-overlay: rgba(31, 35, 40, 0.42);
    --color-surface-scrim: rgba(255, 255, 255, 0.82);
    --color-input-veil: rgba(255, 255, 255, 0.42);
    --color-hover-veil: rgba(0, 0, 0, 0.025);

    /* CodeMirror syntax colors (see XmlCodeEditor highlight style) */
    --cm-tag: #116329;
    --cm-attribute: #0550ae;
    --cm-value: #0a3069;
    --cm-comment: #6e7781;
    --cm-meta: #6639ba;
    --cm-punctuation: #57606a;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
    --space-6: 40px;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --font-size-sm: 12px;
    --font-size-md: 14px;
    --font-size-lg: 16px;
    --font-size-xl: 20px;
    --font-size-xxl: 24px;

    /* Borders */
    --border-radius: 6px;
    --border-radius-sm: 4px;
    --border-radius-lg: 8px;

    /* Shadows */
    --shadow-sm: 0 1px 0 rgba(31, 35, 40, 0.04);
    --shadow-md: 0 3px 6px rgba(140, 149, 159, 0.15);
    --shadow-lg: 0 8px 24px rgba(140, 149, 159, 0.2);
    --app-toolbar-level-1: 52px;
    --app-toolbar-level-2: 44px;
    --app-panel-header-height: 32px;
    --app-inline-notice-padding: 5px var(--space-2);
}

/* ── Dark theme (token overrides only — components inherit via var()) ── */
:root[data-theme="dark"] {
    color-scheme: dark;

    --color-header-bg: #161b22;
    --color-header-text: #f0f6fc;
    --color-header-hover: #30363d;
    --color-bg-primary: #0d1117;
    --color-bg-secondary: #161b22;
    --color-bg-tertiary: #21262d;
    --color-border: #30363d;
    --color-border-muted: #21262d;
    --color-text-primary: #e6edf3;
    --color-text-secondary: #9198a1;
    --color-text-muted: #6e7681;
    --color-link: #4493f8;
    --color-accent-fg: #4493f8;
    --color-success: #3fb950;
    --color-success-bg: rgba(46, 160, 67, 0.16);
    --color-danger: #f85149;
    --color-danger-bg: rgba(248, 81, 73, 0.16);
    --color-warning: #d29922;
    --color-warning-bg: rgba(187, 128, 9, 0.16);
    --color-info-bg: rgba(56, 139, 253, 0.16);

    --rgb-accent: 68, 147, 248;
    --rgb-success: 63, 185, 80;
    --rgb-danger: 248, 81, 73;
    --rgb-warning: 210, 153, 34;

    --color-accent-emphasis: #1f6feb;
    --color-accent-emphasis-hover: #316dca;
    --color-success-emphasis: #238636;
    --color-success-emphasis-hover: #2ea043;
    --color-danger-emphasis: #da3633;
    --color-danger-emphasis-hover: #b62324;

    --color-overlay: rgba(1, 4, 9, 0.64);
    --color-surface-scrim: rgba(13, 17, 23, 0.82);
    --color-input-veil: rgba(1, 4, 9, 0.42);
    --color-hover-veil: rgba(255, 255, 255, 0.04);

    --cm-tag: #7ee787;
    --cm-attribute: #79c0ff;
    --cm-value: #a5d6ff;
    --cm-comment: #8b949e;
    --cm-meta: #d2a8ff;
    --cm-punctuation: #8b949e;

    --shadow-sm: 0 1px 0 rgba(1, 4, 9, 0.24);
    --shadow-md: 0 3px 6px rgba(1, 4, 9, 0.5);
    --shadow-lg: 0 8px 24px rgba(1, 4, 9, 0.65);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: 1.5;
    color: var(--color-text-primary);
    background: var(--color-bg-secondary);
    -webkit-font-smoothing: antialiased;
}

#editor-root,
#settings-root,
#review-queue-root,
#workspace-status-root,
#detached-view-root {
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.app-body {
    height: 100vh;
    width: 100vw;
}

a {
    color: var(--color-link);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* ── Header ────────────────────────────────────────────────── */
.app-header {
    background: var(--color-header-bg);
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 var(--space-4);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-header-text);
    font-size: var(--font-size-xl);
    font-weight: 600;
    text-decoration: none;
    margin-right: var(--space-5);
}
.header-logo:hover {
    text-decoration: none;
    opacity: 0.85;
}

.header-logo svg {
    width: 32px;
    height: 32px;
    fill: var(--color-header-text);
}

.header-nav {
    display: flex;
    gap: var(--space-1);
    flex: 1;
}

.header-nav a {
    color: rgba(255, 255, 255, 0.85);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    font-weight: 500;
    transition: all 0.15s ease;
    text-decoration: none;
}
.header-nav a:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    text-decoration: none;
}
.header-nav a.active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-weight: 600;
}

/* ── Sub-header (breadcrumb bar) ───────────────────────────── */
.sub-header {
    background: var(--color-bg-primary);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-md);
    color: var(--color-text-secondary);
}

.breadcrumb-sep {
    color: var(--color-text-muted);
}

.breadcrumb-current {
    font-weight: 600;
    color: var(--color-text-primary);
}

/* ── Main content ──────────────────────────────────────────── */
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: var(--space-4);
    min-height: calc(100vh - 64px);
}

.main-content.full-width {
    max-width: 100%;
    padding: 0;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 5px 16px;
    font-size: var(--font-size-md);
    font-weight: 500;
    font-family: var(--font-family);
    line-height: 20px;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid;
    border-radius: var(--border-radius);
    transition: all 0.2s cubic-bezier(0.3, 0, 0.5, 1);
    appearance: none;
    user-select: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-success-emphasis);
    border-color: rgba(27, 31, 36, 0.15);
    color: #fff;
    box-shadow: 0 1px 0 rgba(27, 31, 36, 0.04), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:hover:not(:disabled) {
    background: var(--color-success-emphasis-hover);
}

.btn-outline {
    background: var(--color-bg-secondary);
    border-color: var(--color-border);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-sm);
}
.btn-outline:hover:not(:disabled) {
    background: var(--color-bg-tertiary);
}

.btn-danger {
    background: var(--color-danger-emphasis);
    border-color: rgba(27, 31, 36, 0.15);
    color: #fff;
}
.btn-danger:hover:not(:disabled) {
    background: var(--color-danger-emphasis-hover);
}

.btn-sm {
    padding: 3px 12px;
    font-size: var(--font-size-sm);
}

.btn-icon {
    padding: 5px 8px;
}

.editor-layout-toggle {
    min-width: 82px;
    height: 28px;
    justify-content: flex-start;
}

.editor-layout-toggle svg {
    width: 16px;
    height: 16px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
}

/* ── Shared React UI primitives ────────────────────────────── */
.ui-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 32px;
    padding: 5px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    cursor: pointer;
    appearance: none;
    user-select: none;
    text-decoration: none;
}

.btn-primary,
.btn-outline,
.btn-danger {
    min-height: 32px;
}

.btn {
    min-height: 32px;
}

.ui-button:hover:not(:disabled),
.ui-button:focus {
    background: var(--color-bg-tertiary);
    outline: none;
    text-decoration: none;
}

.ui-button:focus-visible {
    border-color: var(--color-accent-fg);
    box-shadow: 0 0 0 2px rgba(var(--rgb-accent), 0.16);
}

.ui-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ui-button-sm {
    min-height: 30px;
    padding: 4px 9px;
    font-size: var(--font-size-sm);
}

.ui-button-primary {
    border-color: var(--color-accent-emphasis);
    background: var(--color-accent-emphasis);
    color: #fff;
}

.ui-button-primary:hover:not(:disabled),
.ui-button-primary:focus {
    background: var(--color-accent-emphasis-hover);
}

.ui-button-danger {
    border-color: var(--color-danger-emphasis);
    background: var(--color-danger-emphasis);
    color: #fff;
}

.ui-button-danger:hover:not(:disabled),
.ui-button-danger:focus {
    background: var(--color-danger-emphasis-hover);
    color: #fff;
}

.ui-button-ghost {
    border-color: transparent;
    background: transparent;
}

.ui-icon-button {
    width: 32px;
    padding-inline: 0;
}

.ui-popover {
    position: fixed;
    z-index: 3900;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    box-sizing: border-box;
}

.ui-menu {
    z-index: 4000;
    display: flex;
    flex-direction: column;
    min-width: 220px;
    max-width: min(320px, calc(100vw - 16px));
    max-height: min(420px, calc(100vh - 16px));
    padding: 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ui-menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 32px;
    padding: 6px 10px;
    border: 0;
    border-radius: var(--border-radius-sm);
    background: transparent;
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
}

.ui-menu-item:hover,
.ui-menu-item:focus {
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    outline: none;
}

.ui-menu-item.is-destructive {
    color: var(--color-danger);
}

.ui-menu-item.is-destructive:hover,
.ui-menu-item.is-destructive:focus {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.ui-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    max-width: min(440px, calc(100vw - 16px));
    padding: 4px;
    overflow-x: auto;
}

.ui-toolbar-button {
    flex: 0 0 auto;
    max-width: 132px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ui-form-popover {
    z-index: 4100;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: min(300px, calc(100vw - 16px));
    padding: 10px;
}

.ui-field {
    display: grid;
    gap: 6px;
}

.ui-field-label {
    display: block;
    overflow: hidden;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ui-field-control {
    width: 100%;
    min-height: 32px;
    padding: 5px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
    line-height: 1.3;
}

.ui-field-control:focus {
    border-color: var(--color-accent-fg);
    box-shadow: 0 0 0 2px rgba(var(--rgb-accent), 0.16);
    outline: none;
}

.ui-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: grid;
    place-items: center;
    padding: var(--space-3);
    background: var(--color-overlay);
}

.ui-dialog {
    width: min(520px, 100%);
    max-height: min(720px, calc(100vh - 32px));
    overflow: auto;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
}

.ui-tabs {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
}

.ui-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    min-height: 28px;
    padding: 4px 10px;
    border: 0;
    border-radius: var(--border-radius-sm);
    background: transparent;
    color: var(--color-text-secondary);
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
}

.ui-tab-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.ui-tab-icon svg {
    width: 16px;
    height: 16px;
    display: block;
}

.ui-tab[aria-selected="true"] {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-sm);
}

.app-section-nav {
    flex: 0 1 auto;
    min-width: 0;
}

.app-section-nav-item {
    text-decoration: none;
    white-space: nowrap;
}

.app-section-nav-item:hover {
    text-decoration: none;
}

.app-section-nav-item[aria-current="page"] {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-sm);
}

.panel-header {
    min-height: var(--app-panel-header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 5px var(--space-2);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.panel-header-main,
.panel-header-side,
.panel-header-actions {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.panel-header-main {
    flex: 1 1 auto;
}

.panel-header-side {
    flex: 0 1 auto;
    justify-content: flex-end;
}

.panel-header-title {
    min-width: 0;
    overflow: hidden;
    color: var(--color-text-primary);
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-header-subtitle,
.panel-header-meta {
    min-width: 0;
    overflow: hidden;
    color: var(--color-text-secondary);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inline-notice {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--app-inline-notice-padding);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.3;
}

.inline-notice-info {
    border-color: rgba(var(--rgb-accent), 0.28);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.inline-notice-success {
    border-color: rgba(var(--rgb-success), 0.32);
    background: var(--color-success-bg);
    color: var(--color-success);
}

.inline-notice-warning {
    border-color: rgba(var(--rgb-warning), 0.3);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.inline-notice-error {
    border-color: rgba(var(--rgb-danger), 0.32);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.ui-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 20px;
    padding: 1px 7px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 700;
    line-height: 1.2;
}

.ui-badge-primary {
    border-color: rgba(var(--rgb-accent), 0.32);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.ui-badge-danger {
    border-color: rgba(var(--rgb-danger), 0.32);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.ui-toast {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-lg);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.ui-toast-success {
    border-color: var(--color-success);
    background: var(--color-success-bg);
    color: var(--color-success);
}

.ui-toast-error {
    border-color: var(--color-danger);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.ui-toast-warning {
    border-color: var(--color-warning);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.ui-toast-info {
    border-color: rgba(var(--rgb-accent), 0.28);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.ui-element-handle,
.ui-table-row-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

/* ── Toolbar ───────────────────────────────────────────────── */
.editor-toolbar-stack {
    flex: 0 0 auto;
    display: grid;
    grid-template-rows: var(--app-toolbar-level-1) var(--app-toolbar-level-2);
    min-height: calc(var(--app-toolbar-level-1) + var(--app-toolbar-level-2));
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-primary);
}

.toolbar {
    background: var(--color-bg-secondary);
    border: 0;
    border-radius: 0;
    padding: 0 var(--space-3);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: nowrap;
    min-width: 0;
    overflow: visible;
}

.toolbar-app-tabs {
    height: var(--app-toolbar-level-1);
    justify-content: flex-start;
    border-bottom: 1px solid var(--color-border);
    background: #20252d;
    color: var(--color-header-text);
}

.toolbar-app-tabs .ui-tabs {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
}

.toolbar-app-tabs .ui-tab {
    color: rgba(255, 255, 255, 0.78);
}

.toolbar-app-tabs .ui-tab[aria-selected="true"] {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
}

.toolbar-app-tabs .app-section-nav-item[aria-current="page"] {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
}

.editor-toolbar-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 160px;
    margin-right: var(--space-3);
    color: #fff;
    font-size: var(--font-size-lg);
    font-weight: 700;
    text-decoration: none;
    cursor: default;
    user-select: none;
}

.editor-toolbar-brand:hover {
    text-decoration: none;
}

.profile-switcher {
    position: relative;
    flex: 0 1 280px;
    min-width: 190px;
}

.editor-toolbar-spacer {
    flex: 1 1 auto;
    min-width: 0;
}

.profile-switcher-button {
    width: 100%;
    justify-content: space-between;
    color: rgba(255, 255, 255, 0.88);
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
}

.profile-switcher-button:hover:not(:disabled),
.profile-switcher-button:focus {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

.profile-switcher-button span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-switcher-menu {
    width: min(380px, calc(100vw - 24px));
    max-height: min(70vh, 520px);
    overflow-y: auto;
    left: auto;
    right: 0;
}

.profile-switcher-search {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-2);
    padding: 0 var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    color: var(--color-text-muted);
}

.profile-switcher-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: var(--space-3);
    align-items: center;
}

.profile-switcher-item.active {
    background: var(--color-info-bg);
}

.profile-switcher-item.is-locked {
    color: var(--color-text-muted);
    cursor: not-allowed;
    opacity: 0.58;
}

.profile-switcher-lock {
    display: inline-flex;
    align-items: center;
    color: var(--color-text-muted);
}

.profile-switcher-item span:first-child {
    min-width: 0;
    display: grid;
}

.profile-switcher-item strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-switcher-item em {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-style: normal;
}

.profile-switcher-footer {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.profile-switcher-empty {
    color: var(--color-text-secondary);
    cursor: default;
}

.review-picker-dialog {
    width: min(480px, calc(100vw - 32px));
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
}

.review-picker-header {
    display: grid;
    gap: var(--space-1);
}

.review-picker-header h2 {
    margin: 0;
    font-size: var(--font-size-xl);
}

.review-picker-header p {
    margin: 0;
    color: var(--color-text-secondary);
    line-height: 1.45;
}

.review-picker-body {
    display: grid;
    gap: var(--space-2);
}

.review-picker-options {
    display: grid;
    gap: var(--space-1);
    max-height: 240px;
    overflow: auto;
    padding: var(--space-1);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
}

.review-picker-option {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--border-radius);
    cursor: pointer;
}

.review-picker-option:hover {
    background: var(--color-bg-secondary);
}

.review-picker-option-input {
    margin: 0;
}

.review-picker-state {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.review-picker-error {
    margin: 0;
    padding: var(--space-2);
    color: var(--color-danger);
    background: rgba(var(--rgb-danger), 0.08);
    border: 1px solid rgba(var(--rgb-danger), 0.32);
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
}

.review-picker-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

.profile-switch-modal {
    width: min(560px, calc(100vw - 32px));
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
    overflow: visible;
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: 1.5;
    white-space: normal;
}

.profile-switch-modal-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-3);
    align-items: start;
}

.profile-switch-modal-header > div {
    min-width: 0;
}

.profile-switch-modal-header h2 {
    margin: 0;
    font-size: var(--font-size-lg);
    line-height: 1.35;
}

.profile-switch-modal-header p {
    margin: var(--space-1) 0 0;
    color: var(--color-text-secondary);
    line-height: 1.5;
    white-space: normal;
}

.profile-switch-modal-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
    margin: 0;
}

.profile-switch-modal-meta dt {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.profile-switch-modal-meta dd {
    min-width: 0;
    overflow: hidden;
    color: var(--color-text-primary);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-switch-modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: 0;
}

.profile-lock-banner,
.profile-schema-banner {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
}

.profile-lock-banner,
.profile-schema-banner-warning {
    border-bottom: 1px solid rgba(var(--rgb-warning), 0.45);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.profile-lock-banner-stolen {
    border-bottom-color: rgba(var(--rgb-danger), 0.4);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.profile-schema-banner-error {
    border-bottom-color: rgba(var(--rgb-danger), 0.4);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.profile-lock-banner span,
.profile-schema-banner span {
    min-width: 0;
    flex: 1;
}

.profile-lock-banner button,
.profile-schema-banner button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    min-height: 28px;
    padding: 0 var(--space-2);
    border: 1px solid currentColor;
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-primary);
    color: inherit;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.profile-schema-banner button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.editor-account-menu {
    position: relative;
    flex: 0 0 auto;
}

.editor-topbar-button {
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.editor-topbar-button:hover:not(:disabled),
.editor-topbar-button:focus,
.editor-topbar-button[aria-expanded="true"] {
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
}

.editor-account-button {
    min-width: 88px;
    justify-content: flex-start;
}

.editor-account-menu .editor-account-dropdown {
    top: 100%;
    left: 0;
    right: auto;
    min-width: 160px;
    z-index: 2400;
}

.editor-account-dropdown .dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
}

.editor-account-dropdown .dropdown-item:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.editor-account-dropdown .dropdown-item:disabled:hover {
    background: none;
}

.editor-theme-option-check {
    margin-left: auto;
    color: var(--color-accent-fg);
}

.editor-logout-button {
    color: var(--color-text-primary);
    font-weight: 500;
}

.editor-message-center {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
}

.editor-message-center-button {
    position: relative;
    width: auto;
    min-width: 64px;
    padding-inline: 10px;
}

.editor-message-center-label {
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.editor-message-center-button.has-unread {
    color: #fff;
}

.editor-message-center-success.has-unread {
    border-color: rgba(87, 171, 90, 0.65);
}

.editor-message-center-error.has-unread {
    border-color: rgba(255, 129, 130, 0.72);
}

.editor-message-center-warning.has-unread {
    border-color: rgba(210, 153, 34, 0.72);
}

.editor-message-center-info.has-unread {
    border-color: rgba(121, 192, 255, 0.72);
}

.editor-message-count {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--color-danger-emphasis);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.editor-message-center-panel {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    z-index: 5200;
    width: min(380px, calc(100vw - 24px));
    max-height: min(420px, calc(100vh - 88px));
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.editor-message-center-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: 40px;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border-muted);
    background: var(--color-bg-secondary);
}

.editor-message-center-header strong {
    font-size: var(--font-size-md);
    line-height: 1.2;
}

.editor-message-list {
    min-height: 80px;
    overflow: auto;
}

.editor-message-item {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border-muted);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
}

.editor-message-item:last-child {
    border-bottom: 0;
}

.editor-message-item-success {
    border-left: 3px solid var(--color-success);
}

.editor-message-item-error {
    border-left: 3px solid var(--color-danger);
}

.editor-message-item-warning {
    border-left: 3px solid var(--color-warning);
}

.editor-message-item-info {
    border-left: 3px solid var(--color-accent-fg);
}

.editor-message-time {
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.editor-message-text {
    min-width: 0;
    overflow-wrap: anywhere;
}

.editor-message-empty {
    padding: var(--space-3);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.toolbar-document-actions {
    height: var(--app-toolbar-level-2);
    background: var(--color-bg-primary);
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 var(--space-2);
}

.toolbar-status {
    margin-left: auto;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    min-width: 0;
    flex: 1 1 auto;
}

.editor-document-status {
    margin-left: auto;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.schema-badge {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: none;
    height: 22px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    overflow: hidden;
    position: relative;
    gap: 4px;
}

.schema-badge::before {
    content: "";
    flex: 0 0 auto;
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--color-success);
}

.schema-badge-label {
    flex: 0 0 auto;
    align-self: stretch;
    display: inline-flex;
    align-items: center;
    padding: 0 3px 0 0;
    background: transparent;
    color: var(--color-success);
    border-right: 0;
    font-weight: 700;
}

.schema-badge-name {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.schema-badge.empty .schema-badge-label {
    background: transparent;
    color: var(--color-text-muted);
}

.schema-badge.empty::before {
    background: var(--color-text-muted);
}

.schema-badge.empty .schema-badge-name {
    color: var(--color-text-muted);
    font-family: var(--font-family);
}

.editor-resource-badges {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    flex: 0 1 auto;
    margin-left: auto;
    overflow: hidden;
}

.toolbar-document-actions .editor-resource-badges {
    padding-left: var(--space-2);
    border-left: 1px solid var(--color-border);
}

.schema-badge-compact {
    max-width: none;
}

#active-schema-badge.schema-badge-compact {
    max-width: none;
}

#active-document-badge.schema-badge-compact {
    max-width: none;
}

.toolbar-status-message {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    flex: 0 0 auto;
    min-width: 0;
}

/* ── Editor container ──────────────────────────────────────── */
.editor-wrapper {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-main-panel {
    padding: 0;
}

.editor-container {
    position: relative;
    flex: 1;
    overflow: auto;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
    padding: var(--space-3);
}

.editor-shell .toolbar {
    position: relative;
    z-index: 2000;
    align-items: center;
    overflow: visible;
    white-space: nowrap;
}

.editor-shell .toolbar-app-tabs {
    z-index: 2300;
}

.editor-shell .toolbar-document-actions {
    z-index: 2200;
}

.editor-shell .dropdown-menu {
    z-index: 2100;
}

.editor-view-dropdown {
    flex: 0 0 auto;
}

.editor-view-menu {
    min-width: 180px;
}

.editor-view-menu.align-right {
    right: 0;
    left: auto;
}

.editor-view-menu-item.active {
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    font-weight: 700;
}

.editor-view-menu-item:disabled {
    color: var(--color-text-muted);
    cursor: not-allowed;
    opacity: 0.65;
}

.editor-view-menu-item:disabled:hover {
    background: transparent;
}

.editor-view-select-native {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

.editor-shell-panels {
    position: relative;
    z-index: 1;
    flex: 1;
    min-height: 0;
    display: flex;
    background: var(--color-bg-primary);
    border: 0;
    border-radius: 0;
    overflow: hidden;
}

.editor-shell-panel {
    min-width: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-primary);
}

.editor-shell-panel.active {
    box-shadow: inset 0 0 0 2px rgba(var(--rgb-accent), 0.28);
}

.editor-panel-header {
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 4px var(--space-3);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.editor-panel-header strong {
    color: var(--color-text-primary);
    font-weight: 700;
    white-space: nowrap;
}

.editor-panel-header-actions {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-left: auto;
}

.editor-panel-detach-button {
    width: 28px;
    height: 28px;
    min-height: 28px;
    padding: 0;
}

.editor-legacy-host,
.authentic-view-host {
    min-height: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
}

.editor-shell .editor-container {
    border: none;
    border-radius: 0;
}

.editor-splitter {
    flex: 0 0 6px;
    background: var(--color-border-muted);
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    cursor: col-resize;
}

.editor-splitter:focus-visible {
    outline: 2px solid var(--color-accent-fg);
    outline-offset: -2px;
}

.editor-placeholder-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--space-5);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
}

.editor-placeholder-view h3 {
    margin: 0 0 var(--space-2);
    color: var(--color-text-primary);
    font-size: var(--font-size-xl);
}

.editor-placeholder-view p {
    max-width: 52ch;
}

.editor-html-preview-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-primary);
}

.editor-html-preview-view .preview-body {
    padding: var(--space-2);
    -webkit-user-select: text !important;
    user-select: text !important;
    cursor: text;
}

.editor-html-preview-view .preview-body * {
    -webkit-user-select: text !important;
    user-select: text !important;
}

.editor-html-preview-view .preview-body > *,
.editor-html-preview-view .preview-body .page {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-shadow: none !important;
    box-sizing: border-box !important;
}

.editor-html-preview-view .preview-body > :not(table),
.editor-html-preview-view .preview-body .page {
    border: 0 !important;
    border-radius: 0 !important;
    outline: 0 !important;
}

.editor-html-preview-view .preview-body .page {
    min-height: auto !important;
}

.editor-html-preview-view .preview-body table {
    max-width: 100%;
}

.editor-html-preview-view .preview-body > .editor-view-loading {
    width: max-content !important;
    max-width: calc(100% - var(--space-4)) !important;
    margin: var(--space-4) auto !important;
}

.editor-pdf-preview-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-primary);
}

.pdf-preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    flex: 1;
}

.text-muted {
    color: var(--color-text-secondary);
}

.app-body-detached {
    min-width: 320px;
    overflow: hidden;
    background: var(--color-bg-secondary);
}

.detached-view-shell {
    height: 100vh;
    width: 100vw;
    display: grid;
    grid-template-rows: minmax(46px, auto) auto minmax(0, 1fr);
    overflow: hidden;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
}

.detached-view-topbar {
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.detached-view-title {
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    flex: 1 1 auto;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.detached-view-title strong {
    color: var(--color-text-primary);
    font-size: var(--font-size-md);
    white-space: nowrap;
}

.detached-view-title span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detached-connection {
    flex: 0 0 auto;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 2px var(--space-2);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    font-weight: 700;
}

.detached-connection-live {
    border-color: rgba(var(--rgb-success), 0.35);
    background: rgba(var(--rgb-success), 0.1);
    color: var(--color-success);
}

.detached-connection-stale,
.detached-connection-saved {
    border-color: rgba(var(--rgb-warning), 0.35);
    background: rgba(var(--rgb-warning), 0.1);
    color: var(--color-warning);
}

.detached-connection-disconnected,
.detached-connection-error {
    border-color: rgba(var(--rgb-danger), 0.35);
    background: rgba(var(--rgb-danger), 0.1);
    color: var(--color-danger);
}

.detached-view-actions {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.detached-view-actions .ui-icon-button {
    width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
}

.detached-view-notice {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.detached-view-notice-stale,
.detached-view-notice-saved,
.detached-view-notice-connecting {
    background: rgba(var(--rgb-warning), 0.08);
    color: var(--color-warning);
}

.detached-view-notice-disconnected {
    background: rgba(var(--rgb-danger), 0.08);
    color: var(--color-danger);
}

.detached-view-body {
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-primary);
}

.detached-view-body .editor-html-preview-view,
.detached-view-body .editor-pdf-preview-view {
    min-height: 0;
    flex: 1;
}

.detached-view-error {
    margin: var(--space-4);
}

.editor-raw-xml-view {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
    background: var(--color-bg-primary);
}

.raw-xml-source {
    min-height: 100%;
    margin: 0;
    padding: var(--space-3);
    color: var(--color-text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.55;
    white-space: pre;
    tab-size: 2;
}

.xml-code-editor {
    position: relative;
    min-height: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    overflow: hidden;
}

.xml-code-editor-actions {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: 6px var(--space-2);
    border-bottom: 1px solid var(--color-border-muted);
    background: var(--color-bg-secondary);
}

.xml-code-editor-host {
    min-height: 0;
    flex: 1;
    overflow: hidden;
}

.xml-code-editor .cm-editor {
    height: 100%;
    min-height: 100%;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.55;
}

.xml-code-editor .cm-scroller {
    overflow: auto;
    font-family: var(--font-mono);
}

.xml-code-editor .cm-gutters {
    border-right: 1px solid var(--color-border-muted);
    background: var(--color-bg-secondary);
    color: var(--color-text-muted);
}

.xml-code-editor .cm-activeLine,
.xml-code-editor .cm-activeLineGutter {
    background: rgba(var(--rgb-accent), 0.06);
}

.xml-code-editor .cm-focused {
    outline: none;
}

.xml-code-editor .cm-focused .cm-scroller {
    outline: 2px solid rgba(var(--rgb-accent), 0.24);
    outline-offset: -2px;
}

.translation-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    overflow: hidden;
    padding: var(--space-2);
    background: var(--color-bg-primary);
}

.translation-action-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: nowrap;
    min-height: 34px;
    border-bottom: 1px solid var(--color-border-muted);
}

.translation-action-spacer {
    flex: 1 1 auto;
    min-width: var(--space-4);
}

.translation-status-pill,
.translation-timer,
.translation-pane-badge {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    padding: 1px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.translation-status-translated {
    color: var(--color-success);
}

.translation-status-translating {
    color: var(--color-accent-fg);
}

.translation-status-skipped {
    color: var(--color-warning);
}

.translation-status-failed {
    color: var(--color-danger);
}

.translation-alert {
    padding: 5px var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    line-height: 1.3;
}

.translation-alert-info {
    border-color: rgba(var(--rgb-accent), 0.28);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.translation-alert-warning {
    border-color: rgba(var(--rgb-warning), 0.3);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.translation-alert-error {
    border-color: rgba(var(--rgb-danger), 0.32);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.translation-xml-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
}

.translation-xml-pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    overflow: hidden;
}

.translation-pane-header {
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 5px var(--space-2);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.translation-pane-header strong {
    color: var(--color-text-primary);
    font-size: var(--font-size-md);
    line-height: 1.2;
}

.translation-pane-meta {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    overflow: hidden;
}

.translation-pane-badge {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--color-text-secondary);
}

.translation-xml-source {
    flex: 1;
    min-height: 0;
    margin: 0;
    overflow: hidden;
}

.translation-empty-state {
    display: inline-flex;
    color: var(--color-text-muted);
    font-family: var(--font-family);
}

.review-queue-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-secondary);
}

.review-queue-topbar {
    flex: 0 0 auto;
    min-height: var(--app-toolbar-level-1);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-3);
    border-bottom: 1px solid var(--color-border);
    background: #20252d;
    color: var(--color-header-text);
}

.review-queue-topbar .ui-tabs {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
}

.review-queue-topbar .ui-tab {
    color: rgba(255, 255, 255, 0.78);
}

.review-queue-topbar .ui-tab[aria-selected="true"],
.review-queue-topbar .app-section-nav-item[aria-current="page"] {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
}

.review-queue-workspace {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: var(--space-4);
    overflow: auto;
}

.review-queue-titlebar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-3);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

.review-queue-titlebar h1 {
    margin: 0;
    color: var(--color-text-primary);
    font-size: var(--font-size-xxl);
    line-height: 1.2;
}

.review-queue-titlebar p,
.review-queue-document p,
.review-queue-meta {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.review-queue-list {
    display: grid;
    gap: var(--space-2);
}

.review-queue-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
}

.review-queue-document {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.review-queue-document svg {
    flex: 0 0 auto;
    color: var(--color-accent-fg);
}

.review-queue-document h2 {
    margin: 0;
    overflow: hidden;
    color: var(--color-text-primary);
    font-size: var(--font-size-lg);
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.review-queue-meta {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    white-space: nowrap;
}

.review-queue-status {
    color: var(--color-accent-fg);
    font-weight: 600;
}

.review-queue-open-link {
    justify-self: end;
}

.review-queue-state {
    min-height: 220px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: var(--space-2);
    border: 1px dashed var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
    text-align: center;
}

.review-queue-state strong {
    color: var(--color-text-primary);
    font-size: var(--font-size-lg);
}

.review-queue-state p {
    max-width: 56ch;
    color: var(--color-danger);
}

.chat-view {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-primary);
}

.chat-thread {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    align-content: start;
    gap: var(--space-2);
    padding: var(--space-2);
    overflow: auto;
}

.chat-empty-state,
.chat-view-locked {
    min-height: 160px;
}

.chat-offline-state {
    align-content: center;
    justify-items: start;
    gap: var(--space-3);
}

.chat-offline-retry {
    gap: var(--space-2);
}

.chat-message {
    max-width: min(760px, 88%);
    display: grid;
    gap: 3px;
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
}

.chat-message p {
    margin: 0;
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.markdown-content .markdown-table-scroll {
    max-width: 100%;
    overflow-x: auto;
}

.markdown-content table {
    min-width: 100%;
    width: max-content;
    border-collapse: collapse;
    font-size: inherit;
    line-height: inherit;
}

.markdown-content th,
.markdown-content td {
    padding: 4px 8px;
    border: 1px solid var(--color-border-muted);
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.markdown-content th {
    background: var(--color-bg-secondary);
    font-weight: 700;
}

.chat-message-markdown {
    display: grid;
    gap: var(--space-1);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.chat-message-markdown h4,
.chat-message-markdown h5,
.chat-message-markdown h6,
.chat-message-markdown p,
.chat-message-markdown ul,
.chat-message-markdown ol,
.chat-message-markdown pre,
.chat-message-markdown .markdown-table-scroll {
    margin: 0;
}

.chat-message-markdown h4,
.chat-message-markdown h5,
.chat-message-markdown h6 {
    font-size: var(--font-size-sm);
    line-height: 1.35;
}

.chat-message-markdown ul,
.chat-message-markdown ol {
    display: grid;
    gap: 2px;
    padding-left: var(--space-4);
}

.chat-message-markdown code {
    padding: 1px 4px;
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-tertiary);
    font-family: var(--font-family-mono);
    font-size: 0.92em;
}

.chat-message-markdown pre {
    overflow: auto;
    max-width: 100%;
    padding: var(--space-2);
    border: 1px solid var(--color-border-muted);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-secondary);
}

.chat-message-markdown pre code {
    padding: 0;
    background: transparent;
    white-space: pre;
}

.chat-working-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.chat-timer {
    color: var(--color-text-secondary);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.chat-message-author {
    justify-self: end;
    border-color: rgba(var(--rgb-accent), 0.24);
    background: var(--color-info-bg);
}

.chat-message-system {
    border-color: var(--color-border-muted);
    background: var(--color-bg-secondary);
}

.chat-error {
    flex: 0 0 auto;
    margin: 0 var(--space-2) var(--space-2);
}

.chat-composer {
    flex: 0 0 auto;
    display: grid;
    gap: var(--space-2);
    padding: var(--space-2);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.chat-composer label {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.chat-input {
    resize: vertical;
    min-height: 72px;
    max-height: 180px;
}

.chat-composer p {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.35;
}

.comment-thread-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-primary);
}

.comment-thread-header {
    flex: 0 0 auto;
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.comment-thread-header h2 {
    margin: 0;
    color: var(--color-text-primary);
    font-size: var(--font-size-lg);
    line-height: 1.2;
}

.comment-thread-header p {
    max-width: 28ch;
    overflow: hidden;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.comment-thread-header-actions {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.comment-thread-anchor {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 32px;
    padding: 5px var(--space-2);
    border-bottom: 1px solid var(--color-border-muted);
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
    font-size: 12px;
}

.comment-thread-anchor span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.comment-thread-filters {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2);
    border-bottom: 1px solid var(--color-border-muted);
    overflow-x: auto;
}

.comment-thread-filter span {
    min-width: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.24);
    font-size: 11px;
    line-height: 1.4;
}

.comment-thread-filter.ui-button-default span {
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
}

.comment-thread-list {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    align-content: start;
    gap: var(--space-2);
    padding: var(--space-2);
    overflow: auto;
}

.comment-thread-card {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
}

.comment-thread-card.is-orphan {
    border-color: rgba(var(--rgb-warning), 0.42);
    background: rgba(var(--rgb-warning), 0.06);
}

.comment-thread-card header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-2);
}

.comment-thread-card header div {
    min-width: 0;
    display: grid;
    gap: 1px;
}

.comment-thread-card strong {
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    line-height: 1.2;
}

.comment-thread-card header span {
    color: var(--color-text-secondary);
    font-size: 11px;
}

.comment-thread-body {
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.comment-thread-path {
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    overflow-wrap: anywhere;
}

.comment-thread-card-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.comment-thread-replies {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding-left: var(--space-3);
    border-left: 2px solid var(--color-border);
}

.comment-thread-reply-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-1);
    min-width: 0;
}

.comment-thread-reply-row > .comment-thread-card {
    flex: 1;
    min-width: 0;
}

.comment-thread-reply-icon {
    color: var(--color-text-secondary);
    flex: 0 0 auto;
    margin-top: 6px;
}

.comment-thread-reply-composer {
    display: grid;
    gap: var(--space-1);
    margin-top: var(--space-1);
    padding: var(--space-2);
    background: var(--color-bg-secondary);
    border-radius: var(--border-radius);
}

.comment-thread-reply-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-1);
}

.comment-thread-state {
    min-height: 120px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: var(--space-1);
    color: var(--color-text-secondary);
    text-align: center;
}

.comment-thread-state-error {
    color: var(--color-danger);
}

.comment-thread-composer {
    flex: 0 0 auto;
    display: grid;
    gap: var(--space-2);
    padding: var(--space-2);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.comment-thread-composer label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.comment-thread-input {
    resize: vertical;
    min-height: 68px;
    max-height: 180px;
}

.comment-thread-composer p {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.phase8-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    overflow: auto;
    padding: var(--space-3);
    background: var(--color-bg-primary);
}

.phase8-code-output-frame {
    min-height: 0;
    display: flex;
    flex: 1;
    overflow: hidden;
}

.phase8-code-output.xml-code-editor {
    min-height: 0;
}

.phase8-action-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border-muted);
}

.revision-topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
}

.phase8-inline-check,
.phase8-inline-select {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.phase8-inline-check input {
    margin: 0;
}

.phase8-inline-select .form-input {
    width: auto;
    min-width: 128px;
    height: 28px;
    padding: 3px 28px 3px 8px;
    font-size: var(--font-size-sm);
}

.revision-legend {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    margin-left: auto;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 700;
    text-transform: uppercase;
}

.revision-legend span {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.revision-legend-swatch {
    width: 14px;
    height: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
}

.revision-legend-new {
    border-color: rgba(var(--rgb-success), 0.35);
    background: var(--color-success-bg);
}

.revision-legend-updated {
    border-color: rgba(var(--rgb-accent), 0.3);
    background: var(--color-info-bg);
}

.revision-legend-deleted {
    border-color: rgba(var(--rgb-danger), 0.32);
    background: var(--color-danger-bg);
}

.revision-summary-band {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    overflow: hidden;
}

.revision-workspace {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
    min-height: 480px;
}

.phase8-version-comparison .revision-workspace {
    flex: 0 0 auto;
    min-height: 0;
}

.phase8-version-comparison .revision-workspace .revision-panel:first-child {
    order: 1;
}

.phase8-version-comparison .revision-workspace .revision-panel:nth-child(2) {
    order: 2;
}

.phase8-version-comparison .revision-panel-content {
    flex: 0 0 auto;
    overflow-x: auto;
    overflow-y: scroll;
    scrollbar-gutter: stable;
}

.phase8-version-comparison .phase8-xml-height-collapsed .revision-panel {
    min-height: 0;
}

.phase8-version-comparison .phase8-xml-height-collapsed .revision-panel-content {
    height: 0;
    overflow: hidden;
    padding-bottom: 0;
    padding-top: 0;
}

.phase8-version-comparison .phase8-xml-height-standard .revision-panel-content {
    height: min(420px, var(--phase8-visible-panel-height, 420px));
    max-height: min(420px, var(--phase8-visible-panel-height, 420px));
}

.phase8-version-comparison .phase8-xml-height-expanded .revision-panel-content {
    min-height: 0;
    height: var(--phase8-visible-panel-height, calc(100dvh - 304px));
    max-height: var(--phase8-visible-panel-height, calc(100dvh - 304px));
}

.phase8-version-comparison .revision-workspace.phase8-xml-height-expanded {
    flex: 0 0 auto;
    min-height: 0;
}

.phase8-revision-output-pane {
    flex: 0 0 auto;
    position: relative;
    margin-top: var(--space-3);
}

.phase8-revision-output-code {
    flex: 0 0 auto;
    height: 340px;
    min-height: 240px;
    max-height: min(640px, calc(100dvh - 196px));
    overflow: hidden;
    padding: var(--space-2) 0;
    background: var(--color-bg-secondary);
    scrollbar-gutter: stable;
}

.phase8-revision-output-resize {
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 18px;
    height: 18px;
    border: 0;
    border-radius: var(--border-radius-sm);
    background: linear-gradient(135deg, transparent 0 48%, var(--color-border) 49% 55%, transparent 56% 100%),
        linear-gradient(135deg, transparent 0 64%, var(--color-border) 65% 71%, transparent 72% 100%);
    cursor: ns-resize;
}

.phase8-revision-output-resize:focus-visible {
    outline: 2px solid var(--color-accent-fg);
    outline-offset: 1px;
}

.phase8-revision-output-line {
    grid-template-columns: 48px minmax(0, 1fr);
    padding-right: var(--space-3);
}

.revision-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: box-shadow 0.16s ease, transform 0.16s ease;
}

.revision-panel:hover {
    box-shadow: var(--shadow-lg);
}

.revision-panel-header {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.revision-panel-header strong {
    display: block;
    color: var(--color-text-primary);
    font-size: var(--font-size-md);
    line-height: 1.2;
}

.revision-panel-subtitle {
    display: block;
    color: var(--color-text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1.2;
    text-transform: uppercase;
}

.revision-panel-meta {
    min-width: 0;
    max-width: 260px;
    overflow: hidden;
    color: var(--color-text-secondary);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.revision-panel-header-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--space-2);
    min-width: 0;
}

.revision-panel-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border-muted);
    background: var(--color-bg-primary);
}

.revision-source-select {
    width: auto;
    min-width: 128px;
    height: 28px;
    padding: 3px 28px 3px 8px;
    font-size: var(--font-size-sm);
}

.revision-source-input {
    min-height: 104px;
    border: 0;
    border-bottom: 1px solid var(--color-border-muted);
    border-radius: 0;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.45;
    resize: vertical;
    white-space: pre;
}

.revision-source-input[readonly] {
    background: var(--color-bg-secondary);
}

.revision-panel-content {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: var(--space-2) 0;
    background: var(--color-bg-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.55;
}

.revision-code-line {
    position: relative;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: start;
    min-width: max-content;
    min-height: 26px;
    padding: 2px 48px 2px 0;
    border-left: 4px solid transparent;
    color: var(--color-text-primary);
    transition: background 0.15s ease, opacity 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.revision-code-line:hover {
    background: var(--color-bg-secondary);
}

.revision-code-line.selected {
    box-shadow: inset 0 0 0 1px rgba(var(--rgb-accent), 0.18);
}

.revision-code-line.faded {
    opacity: 0.58;
}

.revision-code-line.phase8-tone-new {
    border-left-color: var(--color-success);
    background: var(--color-success-bg);
    color: var(--color-success);
}

.revision-code-line.phase8-tone-updated {
    border-left-color: #d97706;
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.revision-code-line.phase8-tone-deleted {
    border-left-color: var(--color-warning);
    background: rgba(var(--rgb-warning), 0.08);
    color: var(--color-warning);
}

.revision-code-line.phase8-tone-moved {
    border-left-color: var(--color-warning);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.revision-code-line.revision-deleted code {
    text-decoration: line-through;
    text-decoration-thickness: 1.5px;
}

.revision-code-line.processed {
    border-left-color: var(--color-border) !important;
    background: var(--color-bg-tertiary) !important;
    color: var(--color-text-muted) !important;
    opacity: 0.68;
}

.revision-code-line.processed .revision-xml-tag,
.revision-code-line.processed .revision-xml-attr,
.revision-code-line.processed .revision-xml-value {
    color: var(--color-text-muted) !important;
}

.revision-code-line.revision-inserted {
    animation: revisionExpandIn 0.22s ease-out;
}

.revision-code-line code {
    min-width: 0;
    overflow: visible;
    color: var(--color-text-primary);
    font: inherit;
    white-space: pre;
}

.revision-line-number {
    padding-right: var(--space-2);
    color: var(--color-text-muted);
    font-size: 11px;
    line-height: 1.7;
    text-align: right;
    user-select: none;
}

.revision-action-icon {
    position: absolute;
    top: 50%;
    z-index: 2;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    opacity: 0;
    transform: translateY(-50%) scale(0.96);
    transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.revision-action-icon svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2.5;
}

.revision-code-line:hover .revision-action-icon,
.revision-code-line.phase8-tone-new .revision-action-icon,
.revision-code-line.phase8-tone-updated .revision-action-icon,
.revision-code-line.phase8-tone-deleted .revision-action-icon,
.revision-code-line.phase8-tone-moved .revision-action-icon,
.revision-action-icon:focus-visible {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

.revision-action-icon:hover,
.revision-action-icon:focus-visible {
    border-color: var(--color-accent-emphasis);
    background: var(--color-accent-emphasis);
    color: #fff;
    outline: none;
}

.revision-move-icon {
    left: 8px;
}

.revision-undo-icon {
    right: 14px;
}

.revision-xml-tag {
    color: var(--color-accent-fg);
}

.revision-xml-attr {
    color: var(--color-success);
}

.revision-xml-value {
    color: var(--color-danger);
}

.revision-mark-token {
    color: var(--color-danger);
    font-weight: 700;
}

.revision-empty-code {
    padding: var(--space-4);
    color: var(--color-text-muted);
    text-align: center;
}

.revision-change-strip {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-primary);
}

.revision-change-strip-empty {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.revision-change-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 28px;
    padding: 3px 9px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    cursor: pointer;
}

.revision-change-chip span {
    font-weight: 700;
}

.revision-change-chip strong {
    font-family: var(--font-mono);
    font-size: 11px;
}

.revision-change-chip.selected,
.revision-anchor-selected {
    outline: 2px solid rgba(var(--rgb-accent), 0.28);
    outline-offset: -2px;
}

.revision-anchor-table .phase8-table tbody tr {
    cursor: pointer;
}

@keyframes revisionExpandIn {
    from {
        max-height: 0;
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        max-height: 40px;
        opacity: 1;
        transform: translateY(0);
    }
}

.phase8-input-grid,
.phase8-output-grid,
.phase8-xml-compare-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

.phase8-input-pane,
.phase8-result-block,
.phase8-validation-panel {
    min-width: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
}

.phase8-input-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.phase8-overlay-json-panel {
    margin-top: var(--space-3);
}

.phase8-input-header,
.phase8-output-header {
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border-muted);
    background: var(--color-bg-secondary);
}

.phase8-input-header .form-label,
.phase8-output-header .form-label {
    margin: 0;
}

.phase8-input-header .phase8-panel-title,
.phase8-output-header .phase8-panel-title {
    color: var(--color-text-primary);
    font-size: var(--font-size-md);
    font-weight: 700;
    line-height: 1.2;
}

.phase8-output-header .phase8-panel-meta {
    min-width: 0;
    max-width: 50%;
    overflow: hidden;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 600;
    line-height: 1.2;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.phase8-input-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.phase8-marking-dropdown,
.phase8-apply-dropdown {
    display: inline-flex;
}

.phase8-marking-menu,
.phase8-apply-menu {
    min-width: 156px;
}

.phase8-marking-menu-item.active,
.phase8-apply-menu-item.active {
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    font-weight: 700;
}

.phase8-action-spacer {
    flex: 1 1 auto;
    min-width: var(--space-4);
}

.phase8-height-icons {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

/* Revision-marks toggle (preview panel headers + detached top bar): marks
   visible = accent-highlighted highlighter; marks hidden = plain ghost icon. */
.editor-panel-revision-marks-button[aria-pressed="true"] {
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.phase8-window-icon-button[aria-pressed="true"] {
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.phase8-window-icon-button svg {
    stroke-linecap: round;
    stroke-linejoin: round;
}

.phase8-source-select {
    width: auto;
    min-width: 128px;
    height: 28px;
    padding: 3px 28px 3px 8px;
    font-size: var(--font-size-sm);
}

.phase8-code-input,
.phase8-code-output {
    border: 0;
    border-radius: 0;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.45;
    resize: vertical;
    white-space: pre;
}

.phase8-code-input {
    min-height: 180px;
}

.phase8-code-output {
    min-height: 180px;
    resize: none;
}

.phase8-rich-code-output {
    overflow: hidden;
    padding: 0;
    background: var(--color-bg-primary);
    scrollbar-gutter: stable;
}

.phase8-xml-height-collapsed .phase8-code-output {
    min-height: 0;
    height: 0;
    overflow: hidden;
}

.phase8-xml-height-standard .phase8-code-output {
    height: 220px;
}

.phase8-xml-height-expanded .phase8-code-output {
    min-height: 0;
    height: var(--phase8-visible-panel-height, calc(100dvh - 304px));
    max-height: var(--phase8-visible-panel-height, calc(100dvh - 304px));
}

.phase8-xml-compare-grid.phase8-xml-height-expanded {
    flex: 0 0 auto;
    min-height: 0;
}

.phase8-code-input:focus,
.phase8-code-output:focus {
    box-shadow: inset 0 0 0 2px rgba(var(--rgb-accent), 0.18);
}

.phase8-code-input[readonly],
.phase8-code-output[readonly] {
    background: var(--color-bg-secondary);
}

.phase8-alert {
    padding: var(--space-2) var(--space-3);
    border: 1px solid;
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.phase8-alert-error {
    border-color: rgba(var(--rgb-danger), 0.4);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.phase8-alert-warning {
    border-color: rgba(var(--rgb-warning), 0.5);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.phase8-summary-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(88px, 1fr));
    border-bottom: 1px solid var(--color-border);
}

.phase8-summary-stat {
    display: grid;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    border-right: 1px solid var(--color-border-muted);
    background: var(--color-bg-secondary);
}

.phase8-summary-stat:last-child {
    border-right: 0;
}

.phase8-summary-stat span {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.phase8-summary-stat strong {
    color: var(--color-text-primary);
    font-size: var(--font-size-xl);
    line-height: 1.1;
}

.phase8-table-wrap {
    max-height: 280px;
    overflow: auto;
}

.phase8-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.phase8-table th,
.phase8-table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border-muted);
    text-align: left;
    vertical-align: top;
}

.phase8-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-weight: 700;
}

.phase8-mono {
    font-family: var(--font-mono);
}

.phase8-path {
    max-width: 36ch;
    overflow-wrap: anywhere;
    color: var(--color-text-secondary);
}

.phase8-empty-cell {
    color: var(--color-text-muted);
    text-align: center !important;
}

.phase8-status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    padding: 1px 7px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.phase8-status-text {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    border: 0;
    background: transparent;
    font-size: var(--font-size-sm);
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.phase8-status-text.phase8-tone-updated {
    border: 0;
    background: transparent;
    color: var(--color-success);
}

.phase8-status-text.phase8-tone-deleted {
    border: 0;
    background: transparent;
    color: var(--color-danger);
}

.phase8-status-text.phase8-tone-unchanged {
    border: 0;
    background: transparent;
    color: var(--color-text-secondary);
}

.phase8-tone-new {
    border-color: rgba(var(--rgb-success), 0.35);
    background: var(--color-success-bg);
    color: var(--color-success);
}

.phase8-tone-updated {
    border-color: rgba(var(--rgb-accent), 0.3);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.phase8-tone-deleted {
    border-color: rgba(var(--rgb-danger), 0.32);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.phase8-tone-moved {
    border-color: rgba(var(--rgb-warning), 0.32);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.phase8-tone-unchanged {
    border-color: var(--color-border-muted);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
}

/* ── Phase 8.1: Revision Upgrade view ─────────────────────── */

.phase8-tone-conflict {
    border-color: rgba(var(--rgb-danger), 0.32);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.phase8-tone-revoked {
    border-color: var(--color-border-muted);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
}

.phase8-status-text.phase8-tone-conflict {
    border: 0;
    background: transparent;
    color: var(--color-danger);
}

.phase8-status-text.phase8-tone-revoked {
    border: 0;
    background: transparent;
    color: var(--color-text-secondary);
}

.revision-code-line.phase8-tone-conflict {
    border-left-color: var(--color-danger);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.revision-code-line.phase8-tone-revoked {
    border-left-color: var(--color-border);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
}

.revision-code-line.phase8-tone-conflict .revision-action-icon,
.revision-code-line.phase8-tone-revoked .revision-action-icon {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

.phase8-upgrade-status {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    padding: var(--space-1) var(--space-1) 0;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.phase8-upgrade-status > span {
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.phase8-upgrade-workspace {
    /* The phase8-view flex column must not shrink this row when the
       rev-marks output pane grows below it. */
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: var(--space-3);
    min-height: 0;
    margin-top: var(--space-2);
}

/* Comparison workspace group: one visible box around the change list,
   candidate panel and reference panes, so the height control on its header
   reads as controlling all of them. Minimum collapses the group to the
   header bar. */
.revision-upgrade-group {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-top: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    background: var(--color-bg-secondary);
}

.revision-upgrade-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.revision-upgrade-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
    min-height: 0;
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
}

.revision-upgrade-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.revision-upgrade-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    cursor: pointer;
}

.revision-upgrade-filter.active {
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.revision-upgrade-filter-count {
    font-weight: 700;
}

.revision-upgrade-change-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.revision-upgrade-change-list:focus-visible {
    outline: 2px solid var(--color-accent-fg);
    outline-offset: 1px;
}

.revision-upgrade-option {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    padding: 4px 6px;
    border-left: 3px solid transparent;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
}

.revision-upgrade-option:hover {
    background: var(--color-bg-secondary);
}

.revision-upgrade-option.selected {
    border-left-color: var(--color-accent-fg);
    background: var(--color-info-bg);
}

.revision-upgrade-option-anchor {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--font-size-sm);
}

.revision-upgrade-option-anchor code {
    font-family: var(--font-mono);
    color: var(--color-text-primary);
}

.revision-upgrade-match-badge {
    flex-shrink: 0;
    padding: 0 6px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text-muted);
    font-size: 10px;
    line-height: 16px;
    white-space: nowrap;
}

.revision-upgrade-option-decision {
    margin-left: auto;
    color: var(--color-text-muted);
    font-size: 11px;
}

.revision-upgrade-list-empty {
    padding: var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.revision-upgrade-candidate {
    min-width: 0;
}

.phase8-revision-upgrade .revision-panel-content {
    flex: 0 0 auto;
    overflow-x: auto;
    overflow-y: scroll;
    scrollbar-gutter: stable;
}

/* Minimum height mode hides the group body under the
   .revision-upgrade-group-header bar (RevisionUpgradeView), so no collapsed
   content rules are needed here. */

.phase8-revision-upgrade .phase8-xml-height-standard .revision-panel-content,
.phase8-revision-upgrade .phase8-xml-height-standard .revision-upgrade-change-list {
    height: min(420px, var(--phase8-visible-panel-height, 420px));
    max-height: min(420px, var(--phase8-visible-panel-height, 420px));
}

.phase8-revision-upgrade .phase8-xml-height-expanded .revision-panel-content,
.phase8-revision-upgrade .phase8-xml-height-expanded .revision-upgrade-change-list {
    min-height: 0;
    height: var(--phase8-visible-panel-height, calc(100dvh - 304px));
    max-height: var(--phase8-visible-panel-height, calc(100dvh - 304px));
}

.revision-upgrade-hunk-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    min-width: max-content;
    padding: 4px 8px 4px 52px;
    border-left: 4px solid var(--color-danger);
    background: var(--color-danger-bg);
}

.revision-upgrade-hunk-label {
    color: var(--color-danger);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.revision-upgrade-reference {
    flex: 0 0 auto;
    margin-top: var(--space-3);
}

.revision-upgrade-reference-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 4px 6px;
    border: 0;
    background: transparent;
    color: var(--color-text-primary);
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
}

.revision-upgrade-reference-toggle:focus-visible {
    outline: 2px solid var(--color-accent-fg);
    outline-offset: 1px;
    border-radius: var(--border-radius-sm);
}

.revision-upgrade-reference-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.revision-upgrade-reference-pane .phase8-code-output {
    max-height: 280px;
}

.revision-upgrade-dialog {
    width: min(520px, calc(100vw - 32px));
    padding: var(--space-3);
}

.revision-upgrade-dialog-header h2 {
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-2);
}

.revision-upgrade-dialog-header p {
    color: var(--color-text-secondary);
    font-size: var(--font-size-md);
}

.revision-upgrade-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.phase8-meta-strip {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.phase8-overlay-status-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border-muted);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.phase8-validation-panel {
    padding: 0;
}

.phase8-validation-valid {
    border-color: rgba(var(--rgb-success), 0.35);
}

.phase8-validation-invalid {
    border-color: rgba(var(--rgb-danger), 0.32);
}

.phase8-output-header span {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.phase8-message-list {
    margin: 0;
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
}

.phase8-overlay-message-list {
    border-bottom: 1px solid var(--color-border-muted);
    background: var(--color-bg-primary);
}

.phase8-message-error {
    color: var(--color-danger);
}

.phase8-message-warning {
    color: var(--color-warning);
}

/* ── Phase 8: overlay entry reconciliation cards ─────────── */

.phase8-overlay-entries {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-2) var(--space-3);
    list-style: none;
    /* Long overlays scroll inside the panel instead of growing the page. */
    max-height: min(420px, 60vh);
    overflow-y: auto;
}

.phase8-overlay-entry {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-muted);
    border-radius: 6px;
    background: var(--color-bg-secondary);
}

.phase8-overlay-entry.phase8-entry-warning {
    border-color: rgba(var(--rgb-warning), 0.32);
    background: var(--color-warning-bg);
}

.phase8-overlay-entry.phase8-entry-error {
    border-color: rgba(var(--rgb-danger), 0.32);
    background: var(--color-danger-bg);
}

.phase8-overlay-entry-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.phase8-overlay-entry-ref {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    overflow-wrap: anywhere;
}

.phase8-overlay-entry-reason {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.phase8-overlay-entry-actions {
    display: flex;
    gap: var(--space-1);
    margin-left: auto;
}

.phase8-overlay-entry-reattach {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.phase8-overlay-entry-reattach select {
    max-width: 100%;
}

.phase8-overlay-entry .phase8-overlay-message-list {
    border-bottom: 0;
    background: transparent;
}

.editor-loading {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-scrim);
    backdrop-filter: blur(1px);
}

.editor-loading-panel {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-md);
    color: var(--color-text-secondary);
    font-size: var(--font-size-md);
    font-weight: 600;
}

.editor-view-loading {
    width: max-content;
    max-width: calc(100% - var(--space-4));
    margin: var(--space-4) auto;
}

/* ── Preview panel ─────────────────────────────────────────── */
.preview-panel {
    width: 0;
    overflow: hidden;
    border-left: 1px solid var(--color-border);
    background: var(--color-bg-primary);
    transition: width 0.3s ease;
    display: flex;
    flex-direction: column;
}

.preview-panel.open {
    width: 50%;
    min-width: 400px;
}

.preview-header {
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-2) var(--space-3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-secondary);
}

.preview-body {
    flex: 1;
    overflow: auto;
    padding: var(--space-4);
}

.preview-body iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ── Settings layout ───────────────────────────────────────── */
.settings-app-shell {
    height: 100vh;
    width: 100vw;
    display: grid;
    grid-template-rows: var(--app-toolbar-level-1) minmax(0, 1fr);
    overflow: hidden;
    background: var(--color-bg-secondary);
}

.settings-app-tabs {
    grid-row: 1;
}

.settings-header-spacer {
    margin-left: auto;
}

.settings-layout {
    min-height: 0;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    gap: 0;
    width: 100%;
    max-width: 1260px;
    margin: 0 auto;
    overflow: hidden;
}

.settings-sidebar {
    width: auto;
    min-height: 0;
    padding: var(--space-4) var(--space-3);
    border-right: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    overflow-y: auto;
}

.settings-sidebar a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--border-radius);
    color: var(--color-text-primary);
    font-size: var(--font-size-md);
    text-decoration: none;
    margin-bottom: 2px;
    transition: background 0.15s ease;
}
.settings-sidebar a:hover {
    background: var(--color-bg-tertiary);
    text-decoration: none;
}
.settings-sidebar a.active {
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.settings-sidebar button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: 2px;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--border-radius);
    background: transparent;
    color: var(--color-text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.settings-sidebar button:hover {
    background: var(--color-bg-tertiary);
}

.settings-sidebar button.active {
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.settings-nav-icon {
    width: 55px;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
}

.settings-main {
    height: 100%;
    min-width: 0;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: var(--space-4) var(--space-5) var(--space-6);
}

.settings-section {
    scroll-margin-top: var(--space-4);
}

.settings-section-card {
    margin: 0 0 var(--space-4);
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-sm);
    outline: none;
}

.settings-section-card:focus {
    box-shadow: 0 0 0 2px rgba(var(--rgb-accent), 0.14), var(--shadow-sm);
}

.settings-section-heading {
    margin-bottom: var(--space-4);
}

.settings-section h2 {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.settings-section h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--space-2);
    margin-top: 0;
}

.settings-section p {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-3);
    font-size: var(--font-size-md);
}

.settings-card-spacing {
    margin-bottom: var(--space-4);
}

.settings-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-3);
}

.settings-summary-tile {
    min-height: 86px;
    display: grid;
    gap: var(--space-1);
    align-content: center;
    padding: var(--space-3);
    border: 1px solid var(--color-border-muted);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
}

.settings-summary-tile span {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.settings-summary-tile strong {
    min-width: 0;
    overflow: hidden;
    color: var(--color-text-primary);
    font-size: var(--font-size-lg);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-upload-card {
    display: grid;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.settings-loading-card {
    margin-top: var(--space-4);
}

.settings-empty-compact {
    padding: var(--space-3);
}

.settings-empty-compact .spinner {
    margin: 0 auto var(--space-2);
}

/* ── Profile management ────────────────────────────────────── */
.profile-settings-layout {
    max-width: 1440px;
}

.profile-settings-main {
    display: grid;
    align-content: start;
    gap: var(--space-4);
}

.profile-settings-titlebar,
.profile-page-heading,
.profile-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.profile-page-heading {
    flex-wrap: wrap;
}

.profile-settings-titlebar h1,
.profile-page-heading h2,
.profile-detail-header h2 {
    margin: 0;
    font-size: var(--font-size-xxl);
    line-height: 1.2;
}

.profile-settings-titlebar p,
.profile-page-heading p,
.profile-detail-header p,
.profile-muted {
    margin: var(--space-1) 0 0;
    color: var(--color-text-secondary);
}

.profile-settings-actions,
.profile-card-actions,
.profile-danger-actions,
.profile-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: flex-end;
}

.profile-card-action-menu .ui-menu-item {
    gap: var(--space-2);
}

.profile-page-tools {
    display: flex;
    flex: 1 1 360px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    min-width: 0;
}

.profile-view-toggle {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
}

.profile-view-toggle button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-height: 32px;
    padding: 0 var(--space-2);
    border: 0;
    border-radius: calc(var(--border-radius) - 2px);
    background: transparent;
    color: var(--color-text-secondary);
    font: inherit;
    cursor: pointer;
}

.profile-view-toggle button.active {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-sm);
}

.profile-page,
.profile-detail-page {
    display: grid;
    gap: var(--space-4);
}

.profile-search {
    flex: 1 1 220px;
    width: min(360px, 100%);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-muted);
}

.profile-search input,
.profile-switcher-search input {
    min-width: 0;
    flex: 1;
    height: 36px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--color-text-primary);
    font: inherit;
}

.profile-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-3);
}

.profile-card-grid.profile-card-view-list {
    grid-template-columns: 1fr;
}

.profile-card {
    display: grid;
    gap: var(--space-3);
    align-content: start;
    min-height: 260px;
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-sm);
}

.profile-card-grid.profile-card-view-list .profile-card {
    min-height: auto;
    grid-template-columns: 1fr;
}

.profile-card.is-current {
    border-color: var(--color-accent-fg);
}

.profile-card.is-retired {
    opacity: 0.72;
}

.profile-card-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-3);
    align-items: start;
}

.profile-title-row,
.profile-chip-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.profile-chip-row {
    margin-top: var(--space-2);
}

.profile-chip-row span,
.profile-current-badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    max-width: 100%;
    padding: 0 var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1;
}

.profile-current-badge {
    border-color: var(--color-accent-fg);
    color: var(--color-accent-fg);
}

.profile-card-header p,
.profile-card em,
.profile-config-row em,
.profile-document-list em {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-style: normal;
}

.profile-title-button,
.profile-back-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--color-link);
    font: inherit;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.profile-title-button {
    max-width: 100%;
    overflow: hidden;
    color: var(--color-text-primary);
    font-size: var(--font-size-lg);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-title-button:hover,
.profile-back-button:hover {
    text-decoration: underline;
}

.profile-visibility-dot {
    width: 10px;
    height: 10px;
    margin-top: 7px;
    border-radius: 50%;
    background: var(--color-text-muted);
}

.profile-visibility-public {
    background: var(--color-success);
}

.profile-visibility-private {
    background: var(--color-accent-fg);
}

.profile-meta-grid,
.profile-overview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

.profile-meta-grid dt,
.profile-overview-grid dt {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.profile-meta-grid dd,
.profile-overview-grid dd {
    min-width: 0;
    overflow: hidden;
    color: var(--color-text-primary);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-empty,
.profile-panel {
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-sm);
}

.profile-panel {
    display: grid;
    gap: var(--space-3);
}

.profile-panel-header {
    margin: calc(var(--space-4) * -1) calc(var(--space-4) * -1) 0;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

.profile-panel-header .panel-header-title {
    font-size: var(--font-size-xl);
}

/* Package Versions card header: same look, distinct class so e2e/product
   locators for the configs panel header stay unique. */
.package-versions-header {
    margin: calc(var(--space-4) * -1) calc(var(--space-4) * -1) 0;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

.package-versions-header .panel-header-title {
    font-size: var(--font-size-xl);
}

.profile-subtabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    border-bottom: 1px solid var(--color-border);
}

.profile-subtabs button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 36px;
    padding: 0 var(--space-3);
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--color-text-secondary);
    font: inherit;
    cursor: pointer;
}

.profile-subtabs button[aria-selected="true"] {
    border-bottom-color: var(--color-accent-fg);
    color: var(--color-text-primary);
    font-weight: 700;
}

.profile-config-grid,
.profile-document-list,
.profile-history-list {
    display: grid;
    gap: var(--space-2);
}

.profile-config-templates {
    display: grid;
    gap: var(--space-2);
}

.profile-config-row,
.profile-document-list button,
.profile-history-list button {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-3);
    align-items: center;
    min-height: 56px;
    padding: var(--space-3);
    border: 1px solid var(--color-border-muted);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font: inherit;
}

.profile-document-list button,
.profile-history-list button {
    cursor: pointer;
    text-align: left;
}

.profile-history-list button {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
}

.profile-document-list button {
    grid-template-columns: minmax(0, 1fr) auto;
}

.profile-document-list button:hover,
.profile-history-list button:hover {
    background: var(--color-bg-tertiary);
}

.profile-config-row span,
.profile-document-list span {
    min-width: 0;
    display: grid;
}

.profile-config-row-templates {
    margin-top: var(--space-2);
}

.profile-config-template-list {
    display: grid;
    gap: var(--space-2);
    padding-left: var(--space-2);
}

.profile-config-template-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-muted);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
}

.profile-config-template-item span {
    min-width: 0;
    display: grid;
}

.profile-config-template-item strong,
.profile-config-template-item em {
    min-width: 0;
}

.profile-config-note {
    margin: 0 0 var(--space-2);
}

.profile-settings-lock-banner {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-muted);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.profile-settings-lock-locked {
    border-color: var(--color-success);
    color: var(--color-text-primary);
}

.profile-settings-lock-blocked {
    border-color: var(--color-warning);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.profile-upload-button {
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.profile-upload-button input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.profile-readme-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.profile-readme-editor {
    display: grid;
    gap: var(--space-3);
}

.profile-readme-textarea {
    min-height: 260px;
    font-family: var(--font-family-mono);
    line-height: 1.55;
}

.profile-readme-markdown {
    display: grid;
    gap: var(--space-2);
    max-width: 860px;
    color: var(--color-text-primary);
    line-height: 1.65;
}

.profile-readme-markdown h4,
.profile-readme-markdown h5,
.profile-readme-markdown h6,
.profile-readme-markdown p,
.profile-readme-markdown ul,
.profile-readme-markdown ol,
.profile-readme-markdown pre,
.profile-readme-markdown .markdown-table-scroll {
    margin: 0;
}

.profile-readme-markdown h4 {
    font-size: var(--font-size-lg);
}

.profile-readme-markdown h5,
.profile-readme-markdown h6 {
    font-size: var(--font-size-md);
}

.profile-readme-markdown ul,
.profile-readme-markdown ol {
    padding-left: var(--space-5);
}

.profile-readme-markdown code {
    padding: 1px 5px;
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-tertiary);
    font-family: var(--font-family-mono);
    font-size: 0.92em;
}

.profile-readme-markdown pre {
    overflow: auto;
    padding: var(--space-3);
    border: 1px solid var(--color-border-muted);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
}

.profile-readme-markdown pre code {
    padding: 0;
    background: transparent;
}

.profile-dialog {
    width: min(620px, calc(100vw - 32px));
}

.profile-dialog form,
.profile-dialog-header,
.profile-form-grid {
    display: grid;
    gap: var(--space-3);
}

.profile-form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.profile-dialog-header h2 {
    margin: 0;
}

.profile-dialog-header p {
    color: var(--color-text-secondary);
}

.profile-radio-group,
.profile-starting-point-fields {
    display: grid;
    gap: var(--space-2);
}

.profile-radio-group {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.profile-radio-option {
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    cursor: pointer;
}

.profile-radio-option:has(input:checked) {
    border-color: var(--color-accent-fg);
    background: var(--color-bg-secondary);
    font-weight: 700;
}

.profile-radio-option:has(input:disabled) {
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.profile-form-note {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.profile-textarea {
    min-height: 86px;
    resize: vertical;
}

.profile-inline-link {
    width: max-content;
}

.profile-forked-from {
    font-size: var(--font-size-sm);
}

.profile-inline-link-button {
    background: none;
    border: none;
    padding: 0;
    color: var(--color-accent-fg);
    text-decoration: underline;
    cursor: pointer;
    font: inherit;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

.card-header {
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-4);
    font-weight: 600;
    font-size: var(--font-size-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: var(--space-4);
}

/* ── Upload zone ───────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--space-4);
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--color-bg-secondary);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.upload-zone:hover {
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
}

.upload-zone.drag-over {
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
    box-shadow: 0 0 0 3px rgba(var(--rgb-accent), 0.15);
}

.upload-zone-icon {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border-muted);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-muted);
    margin-bottom: 0;
}

.upload-zone-text {
    font-size: var(--font-size-md);
    color: var(--color-text-secondary);
}

.upload-zone-text strong {
    color: var(--color-accent-fg);
}

.upload-zone.busy {
    pointer-events: none;
    opacity: 0.8;
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
}

.upload-zone.busy .upload-zone-icon {
    display: inline-block;
    animation: spin 1s linear infinite;
}

.upload-zone.busy .upload-zone-text::after {
    content: " — Processing...";
    font-weight: 600;
    color: var(--color-accent-fg);
}

/* ── File info ─────────────────────────────────────────────── */
.file-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
}

.file-info-icon {
    width: 40px;
    height: 40px;
    background: var(--color-success-bg);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--color-success);
}

.file-info-details {
    flex: 1;
}

.file-info-name {
    font-weight: 600;
    font-size: var(--font-size-md);
}

.file-info-meta {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.settings-template-form {
    display: grid;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.settings-template-list {
    display: grid;
    gap: var(--space-2);
}

.settings-template-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
}

.settings-template-details {
    min-width: 0;
}

.settings-template-count {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.settings-template-error {
    margin-top: var(--space-3);
    padding: var(--space-3);
    background: var(--color-danger-bg);
    border: 1px solid rgba(var(--rgb-danger), 0.4);
    border-radius: var(--border-radius);
    color: var(--color-danger);
}

.settings-template-error ul {
    margin-top: var(--space-2);
    padding-left: var(--space-4);
}

/* ── Toast Notifications ───────────────────────────────────── */
.toast-container {
    position: fixed;
    top: calc(var(--app-toolbar-level-1) + var(--space-2));
    right: var(--space-4);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 450px;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 3s forwards;
    border: 1px solid;
}

.toast-success {
    background: var(--color-success-bg);
    color: var(--color-success);
    border-color: rgba(var(--rgb-success), 0.45);
}

.toast-error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border-color: rgba(var(--rgb-danger), 0.4);
}

.toast-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border-color: rgba(var(--rgb-warning), 0.5);
}

.toast-info {
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    border-color: rgba(var(--rgb-accent), 0.45);
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
    to { opacity: 0; transform: translateX(50%); }
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--color-bg-primary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 440px;
    max-width: 90vw;
    animation: modalSlideUp 0.2s ease;
}

.modal-header {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: var(--font-size-lg);
}

.modal-body {
    padding: var(--space-4);
}

.modal-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

.editor-confirm-modal {
    width: min(460px, calc(100vw - 32px));
    overflow: visible;
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: 1.5;
    white-space: normal;
}

.editor-confirm-modal-header {
    font-size: var(--font-size-lg);
    line-height: 1.35;
}

.editor-confirm-modal-body {
    color: var(--color-text-primary);
}

.editor-confirm-modal-body p {
    margin: 0;
}

.editor-confirm-modal-footer {
    flex-wrap: wrap;
}

@keyframes modalSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ── Form elements ─────────────────────────────────────────── */
.form-group {
    margin-bottom: var(--space-3);
}

.form-label {
    display: block;
    font-size: var(--font-size-md);
    font-weight: 600;
    margin-bottom: var(--space-1);
    color: var(--color-text-primary);
}

.form-input {
    width: 100%;
    padding: 5px 12px;
    font-size: var(--font-size-md);
    font-family: var(--font-family);
    line-height: 20px;
    color: var(--color-text-primary);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-accent-fg);
    box-shadow: 0 0 0 3px rgba(var(--rgb-accent), 0.15);
}

/* ── Dropdown ──────────────────────────────────────────────── */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: var(--space-1);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    z-index: 1100;
    display: none;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
    animation: modalSlideUp 0.15s ease;
}

.dropdown-item {
    display: block;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-md);
    color: var(--color-text-primary);
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-family);
    transition: background 0.1s ease;
}

.dropdown-item:hover {
    background: var(--color-bg-secondary);
    text-decoration: none;
}

/* The Open menu sizes to its longest filename instead of collapsing to the
   dropdown min-width, which ellipsized long names at ~220px. */
#open-dropdown {
    width: max-content;
    max-width: min(520px, calc(100vw - 32px));
}

.dropdown-document-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
}

.dropdown-document-item.validation-invalid {
    grid-template-columns: minmax(0, 1fr) auto auto;
}

.dropdown-document-item.is-current-document {
    grid-template-columns: minmax(0, 1fr) auto auto;
}

.dropdown-document-item.validation-invalid.is-current-document {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
}

.dropdown-document-open {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-document-open:disabled {
    color: var(--color-text-muted);
    cursor: default;
}

.dropdown-document-item.validation-invalid .dropdown-document-open {
    color: var(--color-danger);
    font-weight: 700;
}

.dropdown-document-item.validation-warning .dropdown-document-open {
    color: var(--color-warning);
}

.dropdown-document-validation-marker {
    align-self: center;
    margin: 0 var(--space-2);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: var(--color-danger-bg);
    color: var(--color-danger);
    font-size: var(--font-size-xs);
    font-weight: 700;
    line-height: 1.3;
}

.dropdown-document-item.validation-warning .dropdown-document-validation-marker {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.dropdown-document-current-marker {
    align-self: center;
    margin: 0 var(--space-2);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    font-size: var(--font-size-xs);
    font-weight: 700;
    line-height: 1.3;
}

.dropdown-document-delete {
    min-width: 64px;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-left: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-danger);
    cursor: pointer;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.dropdown-document-delete:hover,
.dropdown-document-delete:focus-visible {
    background: var(--color-danger-bg);
    outline: none;
}

.new-template-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.new-template-item-name {
    font-weight: 600;
}

.new-template-item-meta,
.new-doc-template-meta,
.settings-template-description {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.new-doc-template-name {
    font-weight: 600;
}

.new-document-dropdown {
    display: inline-flex;
}

.new-document-menu-toggle {
    min-width: 30px;
    padding-inline: var(--space-2);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    margin-left: -1px;
}

.new-document-dropdown #btn-new {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.dropdown-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-1) 0;
}

.dropdown-header {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
}

/* ── Workspace Status ─────────────────────────────────────── */
.workspace-status-shell {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-secondary);
}

.workspace-status-header {
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 0 var(--space-3);
    background: var(--color-bg-primary);
    border-bottom: 1px solid var(--color-border);
}

.workspace-status-title {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.workspace-status-title svg {
    flex: 0 0 auto;
    color: var(--color-accent-fg);
}

.workspace-status-title h1 {
    margin: 0;
    font-size: 16px;
    line-height: 1.2;
}

.workspace-status-title span {
    display: block;
    color: var(--color-text-secondary);
    font-size: 12px;
    line-height: 1.2;
}

.workspace-status-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.workspace-status-main {
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-3);
    overflow: hidden;
}

.workspace-status-summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    gap: var(--space-2);
}

.workspace-summary-item {
    min-width: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-primary);
    padding: var(--space-2) var(--space-3);
}

.workspace-summary-item span {
    display: block;
    color: var(--color-text-secondary);
    font-size: 12px;
}

.workspace-summary-item strong {
    display: block;
    margin-top: 2px;
    overflow: hidden;
    color: var(--color-text-primary);
    font-size: 15px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-status-grid {
    min-height: 0;
    flex: 1;
    display: grid;
    grid-template-columns: minmax(280px, 34%) minmax(0, 1fr);
    gap: var(--space-3);
}

.workspace-status-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    overflow: hidden;
}

.workspace-status-panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: 42px;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.workspace-status-panel-title h2 {
    margin: 0;
    font-size: 14px;
    line-height: 1.2;
}

.workspace-status-panel-title span {
    min-width: 0;
    overflow: hidden;
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-tree {
    min-height: 0;
    flex: 1;
    padding: var(--space-2);
    overflow: auto;
}

.workspace-tree-node {
    min-width: 0;
}

.workspace-tree-children {
    margin-left: 18px;
    border-left: 1px solid var(--color-border-muted);
    padding-left: 4px;
}

.workspace-tree-row {
    width: 100%;
    min-width: 430px;
    min-height: 28px;
    display: grid;
    grid-template-columns: 16px 18px minmax(120px, 1fr) minmax(136px, max-content) minmax(48px, max-content);
    align-items: center;
    gap: 4px;
    border: 0;
    border-radius: var(--border-radius-sm);
    padding: 3px 6px;
    background: transparent;
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.workspace-tree-row:hover,
.workspace-tree-row:focus {
    background: var(--color-info-bg);
    outline: none;
}

.workspace-tree-row.selected {
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.workspace-tree-caret,
.workspace-tree-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
}

.workspace-tree-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-tree-size {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

.workspace-tree-modified {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: nowrap;
}

.workspace-content-meta {
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border-muted);
    color: var(--color-text-secondary);
    font-size: 12px;
}

.workspace-content-meta span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-content-viewer {
    min-height: 0;
    flex: 1;
    overflow: auto;
    background: var(--color-bg-primary);
}

.workspace-content-viewer pre {
    min-width: max-content;
    margin: 0;
    padding: var(--space-3);
    color: var(--color-text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre;
}

.workspace-message {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-info-bg);
    color: var(--color-text-secondary);
    padding: var(--space-2) var(--space-3);
    font-size: 13px;
}

.workspace-status-main > .workspace-message {
    margin: 0;
}

.workspace-message-error {
    border-color: rgba(var(--rgb-danger), 0.35);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

/* ── Status indicators ─────────────────────────────────────── */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.success { background: var(--color-success); }
.status-dot.danger { background: var(--color-danger); }
.status-dot.warning { background: var(--color-warning); }
.status-dot.muted { background: var(--color-text-muted); }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: var(--space-6);
    color: var(--color-text-muted);
}

.empty-state-compact {
    padding: var(--space-3);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: var(--space-3);
    opacity: 0.5;
}

.empty-state h3 {
    font-size: var(--font-size-xl);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.empty-state p {
    max-width: 400px;
    margin: 0 auto var(--space-4);
}

/* ── Validation panel ──────────────────────────────────────── */
.validation-errors {
    flex: 0 0 auto;
    max-height: min(260px, 28vh);
    overflow: hidden;
    background: var(--color-danger-bg);
    border: 1px solid rgba(var(--rgb-danger), 0.4);
    border-radius: var(--border-radius);
    padding: var(--space-3);
    margin-top: var(--space-3);
}

.validation-errors h4 {
    color: var(--color-danger);
    font-size: var(--font-size-md);
    margin-bottom: var(--space-2);
}

#validation-error-list {
    max-height: min(208px, calc(28vh - 44px));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: var(--space-1);
}

.validation-error-item {
    display: block;
    width: 100%;
    font-size: var(--font-size-sm);
    padding: var(--space-1) 0;
    border: 0;
    background: transparent;
    font-family: var(--font-mono);
    color: var(--color-danger);
    border-bottom: 1px solid rgba(var(--rgb-danger), 0.1);
    text-align: left;
    -webkit-user-select: text;
    user-select: text;
}

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

.validation-error-button {
    cursor: pointer;
}

.validation-error-button:hover,
.validation-error-button:focus-visible {
    color: var(--color-danger);
    text-decoration: underline;
    outline: none;
}

.validation-warning {
    color: var(--color-warning);
}

/* ── Xonomy overrides ──────────────────────────────────────── */
.xonomy .element {
    font-family: var(--font-mono);
}

#xonomy-editor.xonomy.nerd {
    line-height: 1.25;
}

#xonomy-editor.xonomy.nerd .element {
    margin-top: 1px;
    margin-bottom: 1px;
    padding-left: 34px;
}

#xonomy-editor.xonomy.nerd .element .connector {
    top: calc(1em - 6px);
    width: 32px;
}

#xonomy-editor.xonomy.nerd .element.oneliner .connector {
    top: calc(1em - 6px);
}

#xonomy-editor.xonomy.nerd .element > .tag.opening,
#xonomy-editor.xonomy.nerd .element > .tag.closing {
    top: 1px;
}

#xonomy-editor.xonomy.nerd .element .children {
    padding-top: 0;
    padding-bottom: 0;
}

#xonomy-editor.xonomy.nerd .element .children .textnode {
    margin-top: 1px;
    margin-bottom: 1px;
}

#xonomy-editor.xonomy.nerd .element.hasText .children {
    padding-top: 1px;
    padding-bottom: 1px;
}

#xonomy-editor.xonomy.nerd .element > .connector > .plusminus {
    left: -6px;
    z-index: 30;
}

#xonomy-editor.xonomy.nerd .connector > .draghandle {
    left: 16px;
    right: auto;
    z-index: 20;
}

#xonomy-editor.xonomy.laic {
    line-height: 1.25;
    padding: var(--space-2);
    padding-left: 26px;
}

#xonomy-editor.xonomy.laic .element {
    margin-top: 1px;
    margin-bottom: 1px;
    padding-top: 0;
}

#xonomy-editor.xonomy.laic .element > .children {
    padding-left: 18px;
}

#xonomy-editor.xonomy.laic .element > .children > .textnode {
    margin-top: 1px;
    margin-bottom: 1px;
}

/* Hide indentation-only text nodes between elements, but keep the slot
   visible when it is the element's only content: that is the editable
   placeholder of a freshly added text element (e.g. Add <note>), which
   must stay clickable so the author can start typing. */
#xonomy-editor.xonomy.laic .element > .children > .textnode.whitespace:not(:only-child) {
    display: none;
}

#xonomy-editor.xonomy.laic .element > .children > .textnode > .value {
    padding-top: 1px;
    padding-bottom: 1px;
}

#xonomy-editor.xonomy.laic .element > .tag {
    padding-top: 1px;
    padding-bottom: 1px;
}

#xonomy-editor.xonomy.laic .element > .tag.opening,
#xonomy-editor.xonomy.laic .element > .tag.closing {
    top: 1px;
}

#xonomy-editor.xonomy.laic .element > .children,
#xonomy-editor.xonomy.laic .element.hasText .children {
    padding-top: 1px;
    padding-bottom: 1px;
}

#xonomy-editor.xonomy.laic .element > .connector > .plusminus {
    left: -18px;
    top: 5px;
    z-index: 30;
}

#xonomy-editor.xonomy.laic .connector > .draghandle {
    left: 5px;
    right: auto;
    top: 5px;
    z-index: 20;
}

#xonomy-editor.xonomy.laic .element.draggable > .tag {
    padding-left: 24px;
}

#xonomy-editor.xonomy.laic .element.collapsed:not(.oneliner) > .tag {
    display: inline-block;
    max-width: calc(100% - 48px);
}

#xonomy-editor.xonomy.laic .element.collapsed:not(.oneliner) > .childrenCollapsed {
    display: inline-block;
    margin-top: 0;
    margin-left: 6px;
    padding: 0 6px;
    line-height: 1.25;
    vertical-align: middle;
}

#xonomy-editor.xonomy.laic .element.oneliner {
    padding-top: 1px;
}

#xonomy-editor.xonomy.laic .element.oneliner > .tag.opening {
    min-width: 120px;
    margin-right: 6px;
    padding: 1px 6px 1px 24px;
    line-height: 1.4;
}

#xonomy-editor.xonomy.laic .element.oneliner > .connector > .draghandle {
    left: 5px;
    top: 4px;
}

#xonomy-editor.xonomy.laic .element.oneliner > .children {
    padding-left: 0;
}

#xonomy-editor.xonomy.laic .element.hasInlineMenu.hasText > .children {
    padding: 2px 6px 0 18px;
    line-height: 1.4;
}

#xonomy-editor.xonomy.laic .element.hasInlineMenu.hasText .textnode .value,
#xonomy-editor.xonomy.laic .element.hasInlineMenu.hasText .element .textnode .value {
    padding-top: 1px;
    padding-bottom: 1px;
}

/* ── Spinner ───────────────────────────────────────────────── */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent-fg);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
    .revision-workspace {
        grid-template-columns: 1fr;
        min-height: 0;
        gap: var(--space-4);
    }

    .phase8-version-comparison .revision-workspace {
        order: 1;
    }

    .revision-workspace .revision-panel {
        min-height: 300px;
    }

    .phase8-version-comparison .phase8-revision-output-pane {
        order: 2;
        margin-top: var(--space-4);
    }
}

@media (max-width: 768px) {
    .settings-app-shell {
        grid-template-rows: auto minmax(0, 1fr);
    }

    .editor-toolbar-stack {
        grid-template-rows: auto auto;
        min-height: 0;
    }

    .toolbar-app-tabs {
        height: auto;
        min-height: var(--app-toolbar-level-1);
        flex-wrap: wrap;
        align-content: center;
        row-gap: var(--space-2);
        padding: 6px var(--space-2);
        overflow: visible;
    }

    .editor-shell .toolbar-app-tabs {
        z-index: 2300;
    }

    .editor-toolbar-brand {
        min-width: 0;
        margin-right: var(--space-1);
        font-size: var(--font-size-md);
    }

    .editor-toolbar-spacer {
        display: none;
    }

    .toolbar-app-tabs .ui-tabs {
        flex: 1 1 220px;
        min-width: 0;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .toolbar-app-tabs .ui-tab {
        flex: 0 0 auto;
    }

    .editor-account-menu {
        margin-left: auto;
    }

    .editor-message-center-panel {
        position: fixed;
        top: calc(var(--app-toolbar-level-1) + var(--space-2));
        right: var(--space-2);
        width: min(380px, calc(100vw - 16px));
        max-height: min(420px, calc(100vh - 24px));
    }

    .toolbar-document-actions {
        height: auto;
        min-height: var(--app-toolbar-level-2);
        flex-wrap: wrap;
        align-content: flex-start;
        row-gap: var(--space-2);
        padding: 6px var(--space-2);
        overflow: visible;
    }

    .toolbar-document-actions .ui-button,
    .toolbar-document-actions .ui-button-sm {
        min-height: 34px;
    }

    .editor-shell .toolbar {
        overflow: visible;
        white-space: normal;
    }

    .editor-shell .dropdown-menu {
        max-width: calc(100vw - 16px);
        max-height: min(420px, calc(100vh - 16px));
        overflow: auto;
    }

    .editor-view-dropdown .dropdown-menu:not(.align-right) {
        left: 0;
        right: auto;
    }

    .app-header {
        height: auto;
        min-height: 64px;
        flex-wrap: wrap;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
    }

    .header-logo {
        margin-right: 0;
        font-size: var(--font-size-lg);
    }

    .header-logo svg {
        width: 28px;
        height: 28px;
    }

    .header-nav {
        order: 3;
        flex: 1 0 100%;
        overflow-x: auto;
    }

    .settings-layout {
        grid-template-columns: 1fr;
    }

    .settings-sidebar {
        width: 100%;
        display: flex;
        gap: var(--space-1);
        overflow-x: auto;
        overflow-y: hidden;
        border-right: 0;
        border-bottom: 1px solid var(--color-border);
        padding: var(--space-2);
    }

    .settings-sidebar a {
        flex: 0 0 auto;
    }

    .settings-sidebar button {
        flex: 0 0 auto;
        width: auto;
    }

    .profile-switcher {
        flex: 1 1 220px;
        min-width: min(220px, 100%);
    }

    .profile-settings-titlebar,
    .profile-page-heading,
    .profile-detail-header {
        align-items: stretch;
        flex-direction: column;
    }

    .profile-settings-actions,
    .profile-card-actions,
    .profile-danger-actions,
    .profile-dialog-actions {
        justify-content: flex-start;
    }

    .profile-page-tools {
        justify-content: flex-start;
        min-width: 0;
    }

    .profile-form-grid,
    .profile-overview-grid,
    .profile-meta-grid,
    .profile-radio-group {
        grid-template-columns: 1fr;
    }

    .profile-history-list button {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .preview-panel.open {
        width: 100%;
        min-width: unset;
        position: fixed;
        inset: 64px 0 0 0;
        z-index: 900;
    }

    .editor-wrapper {
        height: 100vh;
        min-height: 0;
        flex-direction: column;
        overflow: hidden;
    }

    .editor-main-panel {
        min-height: 0;
        padding: 0;
    }

    .toolbar-separator {
        display: none;
    }

    .toolbar-status {
        margin-left: 0;
        justify-content: flex-start;
    }

    .editor-panel-header {
        min-height: 0;
        align-items: flex-start;
        flex-wrap: wrap;
        padding: 5px var(--space-2);
    }

    .editor-panel-header strong {
        min-height: 22px;
        display: inline-flex;
        align-items: center;
    }

    .editor-document-status {
        width: 100%;
        margin-left: 0;
        flex-wrap: wrap;
        overflow: visible;
        justify-content: flex-start;
        gap: 2px var(--space-2);
        padding-bottom: 1px;
    }

    .toolbar-status-message {
        flex: 0 1 auto;
        max-width: min(100%, 360px);
    }

    #status-text {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .editor-resource-badges {
        flex: 1 1 100%;
        flex-wrap: wrap;
        overflow: visible;
        row-gap: 2px;
    }

    .editor-shell-panels {
        min-height: 0;
    }

    .editor-shell-panels[data-layout="split"] {
        flex-direction: column;
        overflow: hidden;
    }

    .editor-shell-panels[data-layout="split"] .editor-shell-panel {
        flex-basis: auto !important;
        min-height: 0;
    }

    .review-queue-topbar {
        min-height: var(--app-toolbar-level-1);
        flex-wrap: wrap;
        padding: 6px var(--space-2);
    }

    .review-queue-topbar .editor-toolbar-brand {
        min-width: 0;
        margin-right: var(--space-1);
    }

    .review-queue-topbar .ui-tabs {
        flex: 1 1 220px;
        overflow-x: auto;
    }

    .review-queue-workspace {
        padding: var(--space-3);
    }

    .review-queue-titlebar {
        align-items: stretch;
        flex-direction: column;
    }

    .review-queue-row {
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
    }

    .review-queue-meta {
        justify-content: flex-start;
        flex-wrap: wrap;
        white-space: normal;
    }

    .review-queue-open-link {
        justify-self: start;
    }

    .comment-thread-header {
        align-items: stretch;
        flex-direction: column;
    }

    .comment-thread-header p {
        max-width: 100%;
    }

    .comment-thread-header-actions {
        justify-content: space-between;
    }

    .phase8-input-grid,
    .phase8-output-grid,
    .phase8-xml-compare-grid,
    .translation-xml-grid,
    .revision-workspace,
    .phase8-upgrade-workspace,
    .revision-upgrade-reference-grid {
        grid-template-columns: 1fr;
    }

    .phase8-revision-upgrade .revision-upgrade-change-list {
        max-height: 200px;
    }

    .phase8-summary-grid {
        grid-template-columns: repeat(3, minmax(88px, 1fr));
    }

    .editor-splitter {
        display: none;
    }

    .toast-container {
        right: var(--space-2);
        left: var(--space-2);
    }

    .toast {
        min-width: 0;
        max-width: none;
    }

    .settings-main {
        padding: var(--space-3);
    }

    .settings-summary-grid {
        grid-template-columns: 1fr;
    }

    .workspace-status-header {
        min-height: 52px;
        height: auto;
        flex-wrap: wrap;
        padding: var(--space-2) var(--space-3);
    }

    .workspace-status-actions {
        margin-left: auto;
    }

    .workspace-status-summary {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .workspace-status-grid {
        grid-template-columns: 1fr;
        overflow: auto;
    }

    .workspace-tree-panel {
        min-height: 260px;
    }

    .workspace-content-panel {
        min-height: 360px;
    }
}

@media (max-width: 520px) {
    .btn {
        white-space: normal;
    }

    .toolbar-app-tabs {
        gap: var(--space-1);
    }

    .toolbar-app-tabs .ui-tabs {
        order: 3;
        flex-basis: 100%;
    }

    .editor-account-menu {
        margin-left: 0;
    }

    .editor-message-center-panel {
        top: 88px;
    }

    .profile-switcher {
        order: 2;
        flex-basis: 100%;
    }

    .profile-switcher-menu {
        position: fixed;
        top: 92px;
        left: var(--space-2);
        right: var(--space-2);
        width: auto;
    }

    .profile-card-grid {
        grid-template-columns: 1fr;
    }

    .profile-config-row,
    .profile-document-list button {
        grid-template-columns: 1fr;
    }

    .profile-lock-banner,
    .profile-schema-banner,
    .profile-readme-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .profile-switch-modal-header,
    .profile-switch-modal-meta {
        grid-template-columns: 1fr;
    }

    .profile-switch-modal-actions {
        justify-content: flex-start;
    }

    .toolbar-document-actions .ui-button,
    .toolbar-document-actions .ui-button-sm {
        min-height: 36px;
    }

    .editor-layout-toggle {
        min-width: 74px;
    }

    .editor-panel-header {
        gap: 2px;
    }

    .phase8-action-bar,
    .translation-action-bar,
    .phase8-input-header,
    .phase8-output-header,
    .phase8-input-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .phase8-source-select,
    .revision-source-select,
    .phase8-inline-select,
    .phase8-inline-select .form-input {
        width: 100%;
    }

    .phase8-marking-dropdown,
    .phase8-marking-button,
    .phase8-apply-dropdown,
    .phase8-apply-button {
        width: 100%;
    }

    .phase8-action-spacer {
        display: none;
    }

    .translation-action-spacer {
        display: none;
    }

    .phase8-height-icons {
        margin-left: 0;
    }

    .revision-topbar,
    .revision-panel-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .revision-legend {
        margin-left: 0;
        width: 100%;
        flex-wrap: wrap;
    }

    .revision-code-line {
        grid-template-columns: 38px minmax(0, 1fr);
    }

    .phase8-summary-grid {
        grid-template-columns: repeat(2, minmax(88px, 1fr));
    }

    .workspace-status-main {
        padding: var(--space-2);
    }

    .workspace-status-summary {
        grid-template-columns: 1fr;
    }

    .workspace-status-panel-title,
    .workspace-content-meta {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .workspace-status-actions .ui-button span {
        display: none;
    }
}

/* ── Hidden utility ────────────────────────────────────────── */
.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

/* ── Header User Info ─────────────────────────────────────── */
.header-user {
    display: flex;
    align-items: center;
    margin-left: auto;
    color: var(--color-header-text);
    font-size: var(--font-size-md);
    gap: var(--space-2);
}

.header-user a.btn {
    color: var(--color-header-text);
    border-color: rgba(255,255,255,0.3);
    font-size: var(--font-size-sm);
}

.header-user a.btn:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.5);
}

/* ── Read-Only Badge ──────────────────────────────────────── */
.readonly-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--border-radius);
    background: var(--color-warning-bg);
    color: var(--color-warning);
    font-size: var(--font-size-sm);
    font-weight: 600;
    border: 1px solid rgba(var(--rgb-warning), 0.2);
}

@media (max-width: 768px) {
    .header-user {
        margin-left: auto;
    }
}

@media (max-width: 520px) {
    .header-user {
        width: 100%;
        margin-left: 0;
        justify-content: space-between;
    }
}

/* ═══════════════════════════════════════════════════════════════
   SPS Designer (sub-app at /sps-designer)
   ═══════════════════════════════════════════════════════════════ */

.sps-designer-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--color-bg-secondary);
}

.sps-designer-toolbar-stack {
    display: flex;
    flex-direction: column;
}

.sps-designer-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    border-bottom: 1px solid var(--color-border);
}

.sps-designer-topbar-spacer {
    flex: 1;
}

.sps-designer-active-file {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
}

.sps-designer-notice {
    margin: 8px 16px 0;
}

.sps-designer-layout {
    display: grid;
    grid-template-columns: 280px minmax(320px, 1fr) minmax(360px, 1.4fr);
    gap: 12px;
    flex: 1;
    min-height: 0;
    padding: 12px 16px 16px;
}

.sps-designer-files,
.sps-designer-inspector,
.sps-designer-preview {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: auto;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 12px;
}

.sps-designer-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.sps-designer-panel-header h2 {
    margin: 0;
    font-size: var(--font-size-md, 14px);
}

.sps-designer-schema-header {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border-muted);
}

.sps-designer-muted {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.sps-designer-file-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sps-designer-file-list li + li {
    margin-top: 2px;
}

.sps-designer-file-list button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 6px 8px;
    border: none;
    border-radius: var(--border-radius);
    background: transparent;
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.sps-designer-file-list button:hover {
    background: var(--color-bg-tertiary);
}

.sps-designer-file-list button.active {
    background: var(--color-bg-tertiary);
    outline: 1px solid var(--color-accent-fg);
}

.sps-designer-filename {
    font-weight: 600;
    font-size: var(--font-size-sm);
    word-break: break-all;
}

.sps-designer-new-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--color-border-muted);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
}

.sps-designer-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.sps-designer-tree {
    overflow: auto;
    font-size: var(--font-size-sm);
}

.sps-designer-tree-row {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
}

.sps-designer-tree-row.selected {
    background: var(--color-bg-tertiary);
    border-radius: var(--border-radius);
}

.sps-designer-tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex: none;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 0;
}

.sps-designer-tree-name {
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    color: var(--color-text-primary);
    padding: 2px 4px;
    border-radius: var(--border-radius);
}

.sps-designer-tree-name:hover {
    background: var(--color-bg-tertiary);
}

.sps-designer-orphans {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px dashed var(--color-border-muted);
}

.sps-designer-inspector-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding-top: 12px;
}

.sps-designer-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sps-designer-form h3 {
    margin: 12px 0 0;
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-secondary);
}

.sps-designer-element-title {
    font-family: var(--font-family-mono, monospace);
}

.sps-designer-field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
}

.sps-designer-styles {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 12px;
    min-height: 0;
}

.sps-designer-styles-list ul {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
}

.sps-designer-styles-list button {
    width: 100%;
    padding: 4px 8px;
    border: none;
    border-radius: var(--border-radius);
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-family: var(--font-family-mono, monospace);
    font-size: var(--font-size-sm);
    word-break: break-all;
}

.sps-designer-styles-list button:hover {
    background: var(--color-bg-tertiary);
}

.sps-designer-styles-list button.active {
    background: var(--color-bg-tertiary);
    outline: 1px solid var(--color-accent-fg);
}

.sps-designer-styles-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.sps-designer-css-editor {
    width: 100%;
    box-sizing: border-box;
    font-family: var(--font-family-mono, monospace);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    resize: vertical;
}

.sps-designer-json {
    height: 100%;
}

.sps-designer-json-editor {
    flex: 1;
    min-height: 320px;
}

.sps-designer-preview-host {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: var(--color-bg-tertiary);
    border-radius: var(--border-radius);
    padding: 12px;
}

@media (max-width: 1100px) {
    .sps-designer-layout {
        grid-template-columns: 240px minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    }

    .sps-designer-preview {
        grid-column: 1 / -1;
    }
}

/* Schema-mismatch notice hosts an inline repair action (layout only; the
   error presentation itself follows the standard InlineNotice styling). */
.sps-designer-notice.inline-notice-error {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

/* Package Versions card (Phase 6.4) */
.package-versions-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.package-versions-actions .ui-field-control {
    max-width: 340px;
}

.package-versions-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.package-versions-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--color-border-muted);
}

.package-versions-label {
    font-weight: 700;
    min-width: 48px;
    font-family: var(--font-family-mono, monospace);
}

.package-versions-note {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.package-versions-meta {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    white-space: nowrap;
}

.package-versions-muted {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.package-versions-hint {
    margin-top: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-left: 3px solid var(--color-accent-fg);
    border-radius: var(--border-radius-sm);
    background: var(--color-info-bg);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.45;
}

.package-versions-ring-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--color-text-secondary);
    font: inherit;
    font-size: var(--font-size-sm);
    padding: 4px 0;
}

.package-versions-ring .package-versions-row {
    border-bottom: 1px dashed var(--color-border-muted);
}

/* Phase 6.6: grace slot row + publish dialog */
.package-versions-grace {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: var(--space-2) var(--space-3);
    border-left: 3px solid var(--color-accent-fg);
    border-radius: var(--border-radius-sm);
    background: var(--color-info-bg);
    font-size: var(--font-size-sm);
}

.package-versions-grace .ui-field-control {
    max-width: 170px;
}

.package-versions-publish-modal {
    max-width: 460px;
    padding: var(--space-4);
}

.package-versions-publish-modal h2 {
    margin: 0 0 var(--space-2);
    font-size: var(--font-size-lg);
}

.package-versions-publish-modal p {
    margin: 0 0 var(--space-3);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.45;
}

.package-versions-publish-grace {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: var(--space-3);
    font-size: var(--font-size-sm);
}

.package-versions-publish-modal .ui-field-control {
    max-width: 190px;
    margin-bottom: var(--space-3);
}

.package-versions-publish-warning {
    padding: var(--space-2) var(--space-3);
    border-left: 3px solid var(--color-warning);
    border-radius: var(--border-radius-sm);
    background: var(--color-warning-bg);
    color: var(--color-text-primary);
}

.package-versions-publish-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}


/* ── Xonomy dark-theme adapter ─────────────────────────────────
   xonomy.css is vendored third-party CSS; instead of editing it, this
   block re-skins its laic-mode surfaces and bubble menus when the dark
   theme is active. Light theme keeps the vendored look untouched. */
:root[data-theme="dark"] .xonomy.laic {
    background-color: var(--color-bg-primary);
}
:root[data-theme="dark"] .xonomy.laic .element > .tag {
    background-color: var(--color-bg-tertiary);
    box-shadow: 0 0 2px rgba(1, 4, 9, 0.8);
}
:root[data-theme="dark"] .xonomy.laic .element > .tag > .name { color: var(--color-accent-fg); }
:root[data-theme="dark"] .xonomy.laic .element > .tag > .name:hover { color: var(--color-link); }
:root[data-theme="dark"] .xonomy.laic .element > .tag.opening > .attributes > .attribute { border-left-color: var(--color-border); }
:root[data-theme="dark"] .xonomy.laic .element > .tag.opening > .attributes > .attribute > .name { color: var(--color-accent-fg); }
:root[data-theme="dark"] .xonomy.laic .element > .tag.opening > .attributes > .attribute > .name:hover { color: var(--color-link); }
:root[data-theme="dark"] .xonomy.laic .element > .children > .textnode > .value {
    background-color: transparent;
    border-bottom-color: var(--color-text-muted);
}
:root[data-theme="dark"] .xonomy.laic .element > .children > .textnode > .value:hover,
:root[data-theme="dark"] .xonomy.laic .element > .children > .textnode.whitespace > .value:hover,
:root[data-theme="dark"] .xonomy.laic .element > .tag.opening > .attributes > .attribute > .valueContainer:hover {
    color: var(--color-text-primary);
    background-color: var(--color-bg-tertiary);
}
:root[data-theme="dark"] .xonomy.laic .element > .childrenCollapsed {
    color: var(--color-text-muted);
    text-shadow: none;
}
:root[data-theme="dark"] .xonomy.laic .element.collapsed > .childrenCollapsed:hover { background-color: var(--color-bg-tertiary); }
:root[data-theme="dark"] .xonomy.laic .element.hasInlineMenu.hasText > .children { background-color: var(--color-bg-primary); }
:root[data-theme="dark"] .xonomy.laic .element.hasInlineMenu.hasText .element > .tag.opening,
:root[data-theme="dark"] .xonomy.laic .element.hasInlineMenu.hasText .element > .tag.closing { background-color: var(--color-bg-tertiary); }
:root[data-theme="dark"] .xonomy.laic .attribute > .inlinecaption,
:root[data-theme="dark"] .xonomy.laic .element > .inlinecaption { color: var(--color-text-muted); }
:root[data-theme="dark"] .xonomy .tag.focused > .name,
:root[data-theme="dark"] .xonomy .textnode.focused > .value,
:root[data-theme="dark"] .xonomy .attribute.focused .attributeName,
:root[data-theme="dark"] .xonomy .attributeValue.focused { outline-color: var(--color-text-muted); }
:root[data-theme="dark"] .xonomy .childrenCollapsed.focused,
:root[data-theme="dark"] .xonomy .rollouter.focused { background-color: rgba(var(--rgb-warning), 0.25) !important; }

/* Xonomy nerd mode (the tag-level XML tree view) in dark theme */
:root[data-theme="dark"] .xonomy.nerd {
    background-color: var(--color-bg-primary);
}
:root[data-theme="dark"] .xonomy.nerd .element > .tag > .name { color: #ff7b72; }
:root[data-theme="dark"] .xonomy.nerd .element > .tag.opening > .attributes > .attribute > .name { color: #ffa198; }
:root[data-theme="dark"] .xonomy.nerd .element > .tag.opening > .attributes > .attribute > .valueContainer > .value { color: var(--color-text-secondary); }
:root[data-theme="dark"] .xonomy.nerd .element > .children > .textnode > .value { color: var(--color-text-primary); }
:root[data-theme="dark"] .xonomy.nerd .element > .children > .textnode > .value:hover { color: var(--color-text-secondary); }
:root[data-theme="dark"] .xonomy.nerd .element > .children > .textnode.whitespace > .value:hover { background-color: var(--color-bg-tertiary); }
:root[data-theme="dark"] .xonomy.nerd .element .connector { border-top-color: var(--color-border); }
:root[data-theme="dark"] .xonomy.nerd .element .children { border-left-color: var(--color-border); }
:root[data-theme="dark"] .xonomy.nerd .element > .tag.opening > .attributes.rolledout { border-left-color: var(--color-border); }
:root[data-theme="dark"] .xonomy.nerd .element.current > .tag > .name,
:root[data-theme="dark"] .xonomy.nerd .element > .tag.opening > .attributes > .attribute.current > .name,
:root[data-theme="dark"] .xonomy.nerd .element > .tag.opening > .attributes > .attribute > .valueContainer.current {
    background-color: rgba(var(--rgb-warning), 0.25);
}
:root[data-theme="dark"] .xonomy.nerd .element > .children > .textnode.current > .value {
    background-color: rgba(var(--rgb-warning), 0.25) !important;
}
:root[data-theme="dark"] .xonomy.nerd .rollouter { background-color: var(--color-bg-tertiary); }
:root[data-theme="dark"] .xonomy.nerd .rollouter:hover { background-color: rgba(var(--rgb-warning), 0.25); }

/* Xonomy bubble menu (element/attribute pop-up) in dark theme */
:root[data-theme="dark"] #xonomyBubble > div.inside {
    border-color: var(--color-border);
    background-color: var(--color-bg-tertiary);
    box-shadow: var(--shadow-lg);
}
:root[data-theme="dark"] #xonomyBubble > div.inside > #xonomyBubbleContent {
    background-color: var(--color-bg-primary);
    color: var(--color-text-secondary);
}
:root[data-theme="dark"] #xonomyBubble #xonomyBubbleContent div.menuItem {
    background-color: var(--color-bg-primary);
    border-top-color: var(--color-border-muted);
}
:root[data-theme="dark"] #xonomyBubble #xonomyBubbleContent div.menuItem div.menuLabel { background-color: var(--color-bg-primary); }
:root[data-theme="dark"] #xonomyBubble #xonomyBubbleContent div.menuItem:hover,
:root[data-theme="dark"] #xonomyBubble #xonomyBubbleContent div.menuItem div.menuLabel:hover { background-color: var(--color-bg-tertiary); }
:root[data-theme="dark"] #xonomyBubble .menuItem:focus,
:root[data-theme="dark"] #xonomyBubble .menuLabel:focus { background-color: var(--color-bg-tertiary) !important; }
:root[data-theme="dark"] #xonomyBubble #xonomyBubbleContent form { background-color: var(--color-bg-tertiary); }

/* ── CodeMirror dark selection/caret (basicSetup defaults are light) ── */
:root[data-theme="dark"] .xml-code-editor .cm-cursor,
:root[data-theme="dark"] .xml-code-editor .cm-dropCursor {
    border-left-color: var(--color-text-primary);
}
:root[data-theme="dark"] .xml-code-editor .cm-selectionBackground,
:root[data-theme="dark"] .xml-code-editor .cm-content ::selection,
:root[data-theme="dark"] .xml-code-editor .cm-focused .cm-selectionBackground {
    background: rgba(var(--rgb-accent), 0.3) !important;
}
:root[data-theme="dark"] .xml-code-editor .cm-matchingBracket,
:root[data-theme="dark"] .xml-code-editor .cm-nonmatchingBracket {
    background: rgba(var(--rgb-accent), 0.25);
}

/* ── Document surfaces in dark: smart invert ──────────────────
   The Authentic document and the HTML preview render SPS/XSLT-styled
   content authored against white paper (explicit hex colors live in
   the SPS files). Instead of fighting authored styles, dark mode
   inverts lightness while preserving hue. The in-document editing
   chrome (ghost tags, validation tints — token-driven) re-pins the
   light token values so the inversion lands them back on dark-theme
   colors. Fixed-position popups (context menu, attribute asker) are
   siblings of these containers, so their positioning and normal dark
   styling are unaffected. */
:root[data-theme="dark"] .authentic-document,
:root[data-theme="dark"] .editor-html-preview-view .preview-body {
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f6f8fa;
    --color-bg-tertiary: #eef1f5;
    --color-border: #d0d7de;
    --color-border-muted: #d8dee4;
    --color-text-primary: #1f2328;
    --color-text-secondary: #656d76;
    --color-text-muted: #8b949e;
    --color-link: #0969da;
    --color-accent-fg: #0969da;
    --color-accent-emphasis: #0969da;
    --color-accent-emphasis-hover: #0550ae;
    --color-success: #1a7f37;
    --color-success-bg: #dafbe1;
    --color-danger: #cf222e;
    --color-danger-bg: #ffebe9;
    --color-warning: #9a6700;
    --color-warning-bg: #fff8c5;
    --color-info-bg: #ddf4ff;
    --rgb-accent: 9, 105, 218;
    --rgb-success: 26, 127, 55;
    --rgb-danger: 207, 34, 46;
    --rgb-warning: 154, 103, 0;
    --color-input-veil: rgba(255, 255, 255, 0.42);
    --color-hover-veil: rgba(0, 0, 0, 0.025);
    --shadow-sm: 0 1px 0 rgba(31, 35, 40, 0.04);
    --shadow-md: 0 3px 6px rgba(140, 149, 159, 0.15);
    --shadow-lg: 0 8px 24px rgba(140, 149, 159, 0.2);
    filter: invert(0.906) hue-rotate(180deg);
}

/* Undo the inversion for photographic content. */
:root[data-theme="dark"] .authentic-document img,
:root[data-theme="dark"] .authentic-document video,
:root[data-theme="dark"] .editor-html-preview-view .preview-body img,
:root[data-theme="dark"] .editor-html-preview-view .preview-body video {
    filter: invert(1) hue-rotate(180deg);
}

/* ── Xonomy context menu — shared skin ─────────────────────────
   Restyles the Xonomy bubble menu (XML and Hierarchy views) to match
   .authentic-context-menu in authentic-view.css, so all editor views
   share one context-menu look. Keep the two blocks in sync.
   Loaded after lib/xonomy/xonomy.css, so equal-specificity rules win. */

#xonomyBubble.nerd > div.inside,
#xonomyBubble.laic > div.inside {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 2px;
    box-shadow: var(--shadow-lg);
}

#xonomyBubble.nerd > div.inside > #xonomyBubbleContent,
#xonomyBubble.laic > div.inside > #xonomyBubbleContent {
    background-color: var(--color-bg-primary);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: 13px;
}

#xonomyBubble.nerd #xonomyBubbleContent div.menu,
#xonomyBubble.laic #xonomyBubbleContent div.menu {
    max-height: min(420px, calc(100vh - 16px));
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem {
    min-height: 34px;
    /* Keep 7px bottom padding: div.menuLabel negative margins depend on it. */
    padding: 8px 20px 7px 10px;
    border-top: 1px solid var(--color-border-muted);
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: 13px;
    line-height: 1.25;
}

/* Flat rows like .authentic-context-menu-item: no per-item action icons,
   and element/attribute names in captions render as plain label text
   instead of Xonomy's colored monospace "techno" markup. */
#xonomyBubble.nerd #xonomyBubbleContent div.menuItem span.icon,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem span.icon {
    display: none;
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem.techno,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem.techno,
#xonomyBubble.nerd #xonomyBubbleContent div.menuItem .techno,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem .techno {
    color: inherit;
    font-family: inherit;
    font-size: inherit;
}

/* Laic mode hides all punctuation spans; with flat captions the angle
   brackets are part of the label ("Add <note>"), so show them in menus
   to match the XML and Authentic views. */
#xonomyBubble.laic #xonomyBubbleContent div.menuItem .techno span.punc {
    display: inline;
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem .techno span.elName,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem .techno span.elName,
#xonomyBubble.nerd #xonomyBubbleContent div.menuItem .techno span.atName,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem .techno span.atName,
#xonomyBubble.nerd #xonomyBubbleContent div.menuItem .techno span.atValue,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem .techno span.atValue,
#xonomyBubble.nerd #xonomyBubbleContent div.menuItem .techno span.punc,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem .techno span.punc {
    color: inherit;
    font-family: inherit;
    font-weight: inherit;
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem span.explainer,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem span.explainer {
    color: var(--color-text-muted);
    font-family: inherit;
}

/* Xonomy.formatCaption drops the "@" from attribute names and relied on the
   red atName color to mark attributes; with colors flattened, put it back. */
#xonomyBubble.nerd #xonomyBubbleContent div.menuItem .techno span.atName::before,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem .techno span.atName::before {
    content: "@";
}

/* "Recently used" group label: match the Authentic group label — plain
   muted text, no expand/collapse icon, not interactive. The group's items
   keep Xonomy's native submenu indent. The node is tagged .recent-menu-group
   by xsd-to-docspec.js at render time. */
#xonomyBubble.nerd #xonomyBubbleContent div.menuItem.recent-menu-group,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem.recent-menu-group {
    cursor: default;
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem.recent-menu-group > div.menuLabel,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem.recent-menu-group > div.menuLabel {
    padding-left: 10px;
    background-image: none;
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: normal;
    pointer-events: none;
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem.recent-menu-group > div.menuLabel:focus,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem.recent-menu-group > div.menuLabel:focus {
    background-color: var(--color-bg-primary) !important;
    color: var(--color-text-muted);
    outline: none;
}

/* Empty text slots in the Hierarchy (laic) view: the vendored stylesheet
   leaves .textnode.empty without any size and hides its insertion point, so
   a freshly added text element (e.g. Add <note>) rendered a 0x0 click
   target and could not be clicked to start typing. Give the slot a visible,
   clickable placeholder. */
.xonomy.laic .element .children .textnode.empty {
    min-height: 1em;
}

.xonomy.laic .element .children .textnode.empty .value {
    display: inline-block;
    min-width: 4em;
    min-height: 1.2em;
    border-bottom: 1px dashed var(--color-border);
    vertical-align: baseline;
}

.xonomy.laic .element .children .textnode.empty .value:hover,
.xonomy.laic .element .children .textnode.empty .value:focus {
    background-color: var(--color-bg-secondary);
}

/* The bubble's text-editing fields: the vendored stylesheet hardcodes
   color #333333, which is unreadable once the dark theme switches the
   control background dark. Use tokens for both themes. */
#xonomyBubble.nerd #xonomyBubbleContent input,
#xonomyBubble.laic #xonomyBubbleContent input,
#xonomyBubble.nerd #xonomyBubbleContent textarea,
#xonomyBubble.laic #xonomyBubbleContent textarea,
#xonomyBubble.nerd #xonomyBubbleContent input.textbox,
#xonomyBubble.laic #xonomyBubbleContent input.textbox,
#xonomyBubble.nerd #xonomyBubbleContent textarea.textbox,
#xonomyBubble.laic #xonomyBubbleContent textarea.textbox {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
}

#xonomyBubble.nerd #xonomyBubbleContent div.menu > div.menuItem:first-child,
#xonomyBubble.laic #xonomyBubbleContent div.menu > div.menuItem:first-child {
    border-top: 0;
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem:hover,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem:hover {
    background-color: var(--color-bg-secondary);
    color: var(--color-accent-fg);
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem div.menuLabel,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem div.menuLabel {
    background-color: var(--color-bg-primary);
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem div.menuLabel:hover,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem div.menuLabel:hover {
    background-color: var(--color-bg-secondary);
    color: var(--color-accent-fg);
}

#xonomyBubble .menuItem:focus,
#xonomyBubble .menuLabel:focus {
    background-color: var(--color-bg-secondary) !important;
    color: var(--color-accent-fg);
    outline: none;
}

#xonomyBubble.nerd #xonomyBubbleContent div.menuItem span.keyCaption,
#xonomyBubble.laic #xonomyBubbleContent div.menuItem span.keyCaption {
    color: var(--color-text-muted);
}
