/* Document editor  -  builds on the editor chrome and paper styles in sandbox-pdf-editor.css */

/* Title bar + menu bar (Google Docs style) */
.doc-ed__top {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.75rem 0.2rem;
    background: var(--sw-surface);
}

.doc-ed__logo {
    display: inline-flex;
    flex: 0 0 auto;
    color: var(--primary-color);
}

.doc-ed__logo svg {
    width: 30px;
    height: 30px;
}

.doc-ed__top-main {
    flex: 1;
    min-width: 0;
}

.doc-ed__titlebar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.doc-ed__title {
    min-width: 6rem;
    max-width: 100%;
    flex: 0 1 26rem;
    padding: 0.15rem 0.35rem;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: var(--sw-heading);
    font: inherit;
    font-size: 1.05rem;
    font-weight: 600;
}

/* The sandbox stage gives every input a visible border (with a long :not() chain); the title
   and the source view are borderless until hovered or focused. */
.doc-ed .doc-ed__title,
.doc-ed .doc-ed__source {
    border-color: transparent !important;
}

.doc-ed .doc-ed__title:hover:not([readonly]),
.doc-ed .doc-ed__title:focus {
    border-color: var(--sw-border) !important;
    outline: none;
}

.doc-ed__badge {
    flex: 0 0 auto;
    padding: 0.05rem 0.45rem;
    border: 1px solid var(--sw-border);
    border-radius: 4px;
    color: var(--sw-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.doc-ed__titlebar .pdf-ed__save-state {
    margin-left: 0.25rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.78rem;
    color: var(--sw-muted);
}

.doc-ed.is-dirty .doc-ed__save {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 40%, transparent);
}

.doc-ed__menubar {
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
    margin-left: -0.1rem;
}

.doc-ed__menu {
    position: relative;
}

.doc-ed__menu-btn {
    padding: 0.2rem 0.5rem;
    border: none;
    border-radius: 5px;
    background: none;
    color: var(--sw-text);
    font: inherit;
    font-size: 0.88rem;
    cursor: pointer;
}

.doc-ed__menu-btn:hover,
.doc-ed__menu-btn[aria-expanded="true"] {
    background: color-mix(in srgb, var(--sw-muted) 18%, transparent);
}

.doc-ed__menu-btn:focus-visible,
.doc-ed__mi:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.doc-ed__menu-list {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 30;
    min-width: 230px;
    padding: 0.3rem 0;
    border: 1px solid var(--sw-border);
    border-radius: 8px;
    background: var(--sw-surface);
    box-shadow: var(--sw-shadow);
}

.doc-ed__menu-list[hidden] {
    display: none;
}

.doc-ed__menu-list--sub {
    display: none;
    top: -0.35rem;
    left: 100%;
}

.doc-ed__sub {
    position: relative;
}

.doc-ed__sub.is-open > .doc-ed__menu-list--sub {
    display: block;
}

.doc-ed__mi {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.38rem 0.9rem 0.38rem 0.5rem;
    border: none;
    background: none;
    color: var(--sw-text);
    font: inherit;
    font-size: 0.86rem;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}

.doc-ed__mi:hover,
.doc-ed__sub.is-open > .doc-ed__mi {
    background: color-mix(in srgb, var(--sw-muted) 16%, transparent);
}

.doc-ed__mi:disabled {
    opacity: 0.45;
    cursor: default;
}

.doc-ed__mi kbd,
.doc-ed__mi-arrow {
    margin-left: auto;
    padding-left: 1.5rem;
    color: var(--sw-muted);
    font-family: inherit;
    font-size: 0.76rem;
}

.doc-ed__mi-check {
    flex: 0 0 1rem;
    text-align: center;
    color: var(--primary-color);
}

.doc-ed__mi[aria-checked="true"] .doc-ed__mi-check::before {
    content: '✓';
}

.doc-ed__msep {
    height: 1px;
    margin: 0.3rem 0;
    background: var(--sw-border);
}

/* Toolbar view switches */
.doc-ed__view {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--sw-border);
    border-radius: 7px;
}

.doc-ed__view-btn {
    height: 26px;
    padding: 0 0.55rem;
    border: none;
    border-radius: 5px;
    background: none;
    color: var(--sw-muted);
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
}

.doc-ed__view-btn[aria-checked="true"] {
    color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 14%, transparent);
}

.doc-ed__view-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 1px;
}

/* Formatting does nothing while a source view is open */
.doc-ed--source [data-visual-only] {
    opacity: 0.35;
    pointer-events: none;
}

/* Side panel tabs and outline */
.doc-ed__side-tabs {
    margin: -0.2rem 0 0.8rem;
}

.doc-ed__side-tabs .pdf-ed__tab {
    flex: 1;
    padding: 0.35rem 0.3rem;
    font-size: 0.82rem;
}

.doc-ed .pdf-ed__panel + .pdf-ed__panel {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.doc-ed__outline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.doc-ed__outline-item button {
    display: block;
    width: 100%;
    padding: 0.28rem 0.4rem;
    border: none;
    border-radius: 5px;
    background: none;
    color: var(--sw-text);
    font: inherit;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.doc-ed__outline-item button:hover {
    background: color-mix(in srgb, var(--sw-muted) 16%, transparent);
}

.doc-ed__outline-item--h1 button {
    font-weight: 700;
}

.doc-ed__outline-item--h2 button {
    padding-left: 1.1rem;
}

.doc-ed__outline-item--h3 button {
    padding-left: 1.9rem;
    color: var(--sw-muted);
    font-size: 0.8rem;
}

.doc-ed--no-side .pdf-ed__body {
    grid-template-columns: minmax(0, 1fr);
}

.doc-ed--no-side .pdf-ed__side {
    display: none;
}

/* Continuous view: one sheet that grows with the text */
.doc-ed--flow .pdf-page {
    height: auto;
    min-height: var(--page-h, 297mm);
}

.doc-ed--flow .pdf-page__body {
    height: auto;
    overflow: visible;
}

.doc-ed--flow .pdf-page__num {
    display: none;
}

/* Page-break marker (visible in continuous view, turned into sheets in page view) */
.pdf-page__body hr.pdf-pagebreak {
    position: relative;
    height: 0;
    margin: 1.4em -0.5em;
    border: none;
    border-top: 1px dashed #b4b4b4;
    overflow: visible;
}

.pdf-page__body hr.pdf-pagebreak::after {
    content: attr(data-label);
    position: absolute;
    top: -0.75em;
    left: 50%;
    transform: translateX(-50%);
    padding: 0 0.6em;
    background: #fff;
    color: #888;
    font-family: system-ui, sans-serif;
    font-size: 8pt;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Inline code and code blocks on the paper */
.pdf-page__body code {
    padding: 0.05em 0.3em;
    border-radius: 3px;
    background: #f1f1f1;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 0.92em;
}

.pdf-page__body pre {
    margin: 0 0 0.7em;
    padding: 0.7em 0.9em;
    border-radius: 5px;
    background: #f4f4f5;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 9.5pt;
    line-height: 1.45;
    white-space: pre-wrap;
}

.pdf-page__body pre code {
    padding: 0;
    background: none;
}

/* Markdown / HTML source view takes the viewport's place */
.doc-ed__source {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 1.25rem 1.5rem;
    border: none;
    resize: none;
    outline: none;
    background: color-mix(in srgb, var(--sw-surface) 70%, #000 30%);
    color: var(--sw-text);
    font-family: ui-monospace, Consolas, 'Courier New', monospace;
    font-size: 0.88rem;
    line-height: 1.6;
    tab-size: 4;
}

.doc-ed__source[hidden],
.pdf-ed__viewport[hidden] {
    display: none;
}

/* Version history (CMS) */
.doc-ed__versions {
    list-style: none;
    max-height: 50vh;
    margin: 0.5rem 0 0;
    padding: 0;
    overflow-y: auto;
}

.doc-ed__version {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.2rem;
    border-bottom: 1px solid var(--sw-border);
}

.doc-ed__version > span {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.doc-ed__version small {
    color: var(--sw-muted);
    font-size: 0.78rem;
}

@media (max-width: 860px) {
    .doc-ed__logo {
        display: none;
    }

    .doc-ed__source {
        grid-row: 1;
        min-height: 420px;
    }

    .doc-ed__menu-list--sub {
        position: static;
        box-shadow: none;
        border: none;
        border-left: 2px solid var(--sw-border);
        margin-left: 1rem;
        border-radius: 0;
    }
}
