/* The editing workspace is scoped to its dialog; other views keep their layout. */
html:has(#page-dialog[open]), html:has(#page-dialog[open]) body {
    overflow: hidden;
}
#page-dialog {
    position: fixed; inset: 0; width: 100%; height: 100vh; height: 100dvh;
    max-width: none; max-height: none; margin: 0; padding: 0;
    border: 0; border-radius: 0; box-shadow: none; overflow: hidden;
}
#page-dialog[open] { display: block; }
#page-dialog::backdrop { background: var(--paper); backdrop-filter: none; }
#page-dialog > #page-form {
    position: relative; display: grid; grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 56px minmax(0, 1fr) 28px;
    width: 100%; height: 100%; min-height: 0; padding: 0; gap: 0; overflow: hidden;
}
#page-dialog .editor-header { display: flex; align-items: center; gap: 20px; padding: 6px 20px; color: var(--header-fg); background: var(--header-bg); border-bottom: 1px solid var(--header-control-border); }
#page-dialog .editor-document-title { display: flex; align-items: center; gap: 20px; flex: 1; min-width: 0; }
#page-dialog .editor-brand { flex: none; gap: 8px; }
#page-dialog .editor-brand img { width: 32px; height: 32px; flex-basis: 32px; filter: none; }
#page-dialog .editor-brand strong { font-size: 20px; }
#page-dialog .editor-document-title input { min-width: 0; max-width: 760px; padding: 6px 12px 6px 20px; color: inherit; background: transparent; border: 0; border-left: 1px solid var(--header-control-border); border-radius: 0; font-weight: var(--weight-semibold); }
#page-dialog .editor-document-title input::placeholder { color: var(--header-muted); }
#page-dialog .editor-document-title input:focus { border-color: var(--header-control-border); box-shadow: none; outline: 2px solid var(--header-control-border); outline-offset: 2px; }
#page-dialog .editor-document-actions { display: flex; align-items: center; gap: 18px; flex: none; }
#page-dialog #page-form-status { min-width: 0; max-width: min(320px, 23vw); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--header-muted); font-size: var(--text-xs); }
#page-dialog #page-form-status[data-error] { font-weight: var(--weight-semibold); text-decoration: underline; text-decoration-style: dotted; }
#page-dialog .editor-document-actions .button.primary { color: var(--accent); background: var(--paper-strong); }
html[data-theme="dark"] #page-dialog .editor-document-actions .button.primary { color: var(--on-brand); background: var(--brand-surface); }
#page-dialog .markdown-editor { position: relative; width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 0; grid-template-rows: 50px minmax(0, 1fr) auto; overflow: visible; }
#page-dialog .markdown-toolbar { position: relative; z-index: 5; min-width: 0; gap: 2px; padding: 8px 20px; background: var(--paper-strong); border-bottom-color: var(--line); }
#page-dialog .editor-format-tools { display: flex; flex: 0 1 auto; min-width: 0; gap: 2px; overflow-x: auto; scrollbar-width: none; }
#page-dialog .editor-format-tools::-webkit-scrollbar { display: none; }
#page-dialog .markdown-toolbar [data-markdown] { width: 32px; height: 32px; min-width: 32px; flex: none; color: var(--muted); background: transparent; border: 0; border-radius: 4px; }
#page-dialog .markdown-toolbar [data-markdown]:hover { color: var(--ink); background: var(--surface-subtle); }
#page-dialog .editor-tool { display: flex; align-items: center; gap: 8px; height: 32px; flex: none; padding: 4px 8px; color: var(--muted); background: transparent; border: 0; font-size: var(--text-sm); }
#page-dialog .editor-tool svg { width: 16px; height: 16px; fill: currentColor; }
#page-dialog .editor-tool[aria-pressed="true"] { color: var(--selected-text); background: var(--selected-surface); }
#page-dialog .editor-tool-separator { width: 1px; height: 20px; margin: 0 12px; background: var(--line); flex: none; }
#page-dialog .editor-keywords { position: relative; flex: none; }
#page-dialog .editor-keywords > summary { display: flex; align-items: center; gap: 8px; height: 32px; padding: 4px 8px; color: var(--muted); list-style: none; border-radius: 4px; font-size: var(--text-sm); cursor: pointer; }
#page-dialog .editor-keywords > summary::-webkit-details-marker { display: none; }
#page-dialog .editor-keywords[open] > summary { color: var(--selected-text); background: var(--selected-surface); }
#page-dialog #editor-keyword-count { min-width: 20px; padding: 0 4px; text-align: center; border-radius: 4px; color: var(--selected-text); background: var(--selected-surface); font-size: var(--text-xs); font-weight: var(--weight-semibold); }
#page-dialog .editor-menu-caret { font-size: 12px; }
#page-dialog .editor-keywords-panel { position: absolute; top: calc(100% + 10px); left: 0; width: 340px; max-width: calc(100vw - 24px); padding: 18px; color: var(--ink); background: var(--paper-strong); border: 1px solid var(--line); border-radius: .5rem; box-shadow: var(--shadow); }
#page-dialog .editor-keywords-panel label { gap: 10px; }
#page-dialog .editor-keywords-panel textarea { min-height: 82px; font-family: var(--font-sans); font-weight: var(--weight-regular); }
#page-dialog .editor-keywords-panel p { margin: 12px 0; color: var(--muted); font-size: var(--text-sm); line-height: var(--leading-sm); }
#page-dialog .editor-keywords-panel small { display: block; padding-top: 12px; color: var(--muted); border-top: 1px solid var(--line); font-size: var(--text-xs); }
#page-dialog .editor-tabs { display: flex; flex: none; gap: 0; margin-left: auto; padding: 2px; background: var(--surface-subtle); border-radius: 5px; }
#page-dialog .editor-tabs button { min-width: 54px; height: 28px; padding: 3px 10px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-size: var(--text-xs); }
#page-dialog .editor-tabs button.active { color: var(--selected-text); background: var(--paper-strong); box-shadow: 0 1px 3px rgb(9 30 66 / 12%); }
#page-dialog .editor-body { position: relative; display: grid; grid-template-columns: 0 minmax(0, 1fr); min-height: 0; overflow: hidden; }
#page-dialog[data-outline-open] .editor-body { grid-template-columns: 216px minmax(0, 1fr); }
#page-dialog .editor-outline { display: grid; grid-template-rows: 40px minmax(0, 1fr) auto; grid-column: 1; grid-row: 1; min-width: 0; min-height: 0; background: var(--paper); border-right: 1px solid var(--line); }
#page-dialog .editor-outline-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border-bottom: 1px solid var(--line); }
#page-dialog .editor-outline-heading strong { font-size: var(--text-sm); }
#page-dialog .editor-outline-heading button { min-width: 28px; min-height: 28px; color: var(--muted); font-size: 20px; }
#page-dialog #editor-outline-items { min-height: 0; overflow: auto; padding: 10px 8px; }
#page-dialog .editor-outline-item { display: block; width: 100%; min-height: 34px; padding: 7px 10px; color: var(--muted); background: transparent; border: 0; border-radius: 4px; text-align: left; font-size: var(--text-sm); line-height: var(--leading-sm); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; cursor: pointer; }
#page-dialog .editor-outline-item[data-depth="1"] { color: var(--ink); font-weight: var(--weight-semibold); }
#page-dialog .editor-outline-item[data-depth="2"] { padding-left: 24px; }
#page-dialog .editor-outline-item[data-depth="3"] { padding-left: 40px; font-size: var(--text-xs); }
#page-dialog .editor-outline-item[aria-current="location"] { color: var(--selected-text); background: var(--selected-surface); }
#page-dialog .editor-outline > small { padding: 12px 14px; color: var(--muted); border-top: 1px solid var(--line); font-size: var(--text-xs); line-height: var(--leading-xs); }
#page-dialog #editor-outline-empty { grid-row: 2; margin: 0; font-size: var(--text-sm); }
#page-dialog .editor-split { display: grid; grid-column: 2; grid-row: 1; grid-template-columns: calc(50% + .5px) calc(50% - .5px); min-width: 0; height: 100%; overflow: hidden; }
#page-dialog .editor-source { min-height: 0; border-right-color: var(--line); }
#page-dialog .editor-source textarea, #page-dialog .editor-preview { padding: 20px 28px; }
#page-dialog .editor-reading-layout, #page-dialog .editor-reading-content { min-width: 0; }
#page-dialog:not([data-editor-view="preview"]) :is(.editor-site-navigation, .editor-preview-hero, .editor-firmware-placeholder) { display: none; }
#page-dialog:not([data-editor-view="preview"]) .editor-page-preview { padding: 0; }
#page-dialog:not([data-editor-view="preview"]) .editor-page-preview > .page-columns { display: block; padding: 0; }
#page-dialog[data-editor-view="preview"] .editor-preview { padding: 0; scrollbar-gutter: auto; }
#page-dialog[data-editor-view="preview"] .editor-reading-layout { display: grid; grid-template-columns: var(--navigation-width) minmax(0, 1fr); min-height: 100%; }
#page-dialog[data-editor-view="preview"] .editor-reading-content { container: main-content / inline-size; background: var(--paper); }
#page-dialog .editor-site-navigation { position: sticky; top: 0; align-self: start; display: flex; flex-direction: column; gap: 8px; height: calc(100dvh - 134px); padding: 20px 16px; color: var(--muted); background: var(--paper-strong); border-right: 1px solid var(--line); font-size: var(--text-sm); }
#page-dialog .editor-site-navigation > strong { color: var(--ink); }
#page-dialog .editor-site-navigation small, #page-dialog .editor-site-navigation p, #page-dialog .editor-firmware-placeholder small { color: var(--muted); font-size: var(--text-xs); line-height: var(--leading-xs); }
#page-dialog .editor-site-navigation p { margin: 16px 0 0; }
#page-dialog .editor-navigation-lines, #page-dialog .editor-firmware-lines { display: grid; gap: 18px; margin-top: 16px; }
#page-dialog :is(.editor-navigation-lines, .editor-firmware-lines) > i { display: block; width: 80%; height: 8px; border-radius: 3px; background: var(--surface-muted); }
#page-dialog .editor-navigation-lines > i:nth-child(even) { width: 60%; margin-left: 16px; }
#page-dialog .editor-firmware-lines { gap: 10px; margin: 0; }
#page-dialog .editor-firmware-lines > i:last-child { width: 55%; }
#page-dialog .editor-firmware-placeholder p { margin: 0; color: var(--muted); font-size: var(--text-sm); }
#page-dialog .editor-firmware-placeholder button:disabled { cursor: default; }
#page-dialog .editor-source.tab-hidden, #page-dialog .editor-preview.tab-hidden { display: none !important; }
#page-dialog[data-editor-view="source"] .editor-split, #page-dialog[data-editor-view="preview"] .editor-split { grid-template-columns: minmax(0, 1fr); }
#page-dialog .editor-outline-scrim { display: none; }
#page-dialog .editor-image-drop { inset: 50px 0 0; }
#page-dialog .editor-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 20px; color: var(--muted); background: var(--surface-subtle); border-top: 1px solid var(--line); }
#page-dialog .editor-footer small, #page-dialog .editor-footer button { color: var(--muted); font-size: var(--text-xs); line-height: var(--leading-xs); }
#page-dialog .editor-footer button { padding: 4px 0; background: transparent; }
@media (max-width: 900px) {
    #page-dialog[data-editor-view="preview"] .editor-reading-layout { grid-template-columns: minmax(0, 1fr); }
    #page-dialog[data-editor-view="preview"] .editor-site-navigation { display: none; }
    #page-dialog .editor-brand strong { display: none; }
    #page-dialog .editor-tabs [data-editor-tab="split"] { display: none; }
    #page-dialog .editor-body, #page-dialog[data-outline-open] .editor-body { grid-template-columns: minmax(0, 1fr); }
    #page-dialog .editor-split { grid-column: 1; }
    #page-dialog .editor-outline { position: absolute; z-index: 4; inset: 0 auto 0 0; width: min(272px, calc(100% - 48px)); height: 100%; box-shadow: var(--shadow); }
    #page-dialog[data-outline-open] .editor-outline-scrim { display: block; position: absolute; z-index: 3; inset: 0; width: 100%; border: 0; background: rgb(9 30 66 / 25%); }
}
@media (max-width: 600px) {
    #page-dialog > #page-form { grid-template-rows: 56px minmax(0, 1fr) 42px; }
    #page-dialog .editor-header { gap: 8px; padding-inline: 12px; }
    #page-dialog .editor-document-title { gap: 8px; }
    #page-dialog .editor-document-title input { padding-inline: 8px; font-size: var(--text-sm); }
    #page-dialog .editor-document-actions { gap: 6px; }
    #page-dialog .editor-document-actions .button { min-height: 34px; padding: 6px 10px; }
    #page-dialog #editor-close { min-width: 28px; }
    #page-dialog #page-form-status { position: absolute; z-index: 1; left: 12px; right: 84px; bottom: 4px; display: flex; align-items: center; height: 34px; max-width: none; overflow: auto; white-space: normal; color: var(--muted); font-size: var(--text-xs); line-height: var(--leading-xs); }
    #page-dialog .markdown-toolbar { padding-inline: 8px; }
    #page-dialog #editor-outline-toggle { min-width: 32px; padding: 4px 8px; }
    #page-dialog #editor-outline-toggle > span { display: none; }
    #page-dialog .editor-tool-separator { margin-inline: 4px; }
    #page-dialog .editor-keywords > summary { gap: 4px; padding-inline: 6px; }
    #page-dialog #editor-keyword-count { display: none; }
    #page-dialog .editor-keywords-panel { position: fixed; top: 104px; left: 12px; right: 12px; width: auto; max-width: none; }
    #page-dialog .editor-tabs button { min-width: 38px; padding-inline: 5px; }
    #page-dialog .editor-source textarea, #page-dialog .editor-preview { padding: 16px; }
    #page-dialog .editor-source { height: 100%; border-right: 0; }
    #page-dialog .editor-footer { padding-inline: 12px; justify-content: end; }
    #page-dialog #editor-image-help { display: none; }
    #page-dialog .editor-image-upload { grid-template-columns: minmax(0, 1fr) 4rem auto; }
}

#page-dialog .editor-upload-help { display: flex; align-items: center; gap: 12px; min-width: 0; overflow: hidden; }
#page-dialog .editor-upload-help small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#page-dialog .editor-footer button { flex-shrink: 0; }
