/* PDF editor  -  extends .sandbox-widget */
.pdf-ed.sandbox-widget {
    position: relative;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Toolbar */
.pdf-ed__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--sw-border);
    background: var(--sw-surface);
}

.pdf-ed__tb-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding-right: 0.5rem;
    border-right: 1px solid color-mix(in srgb, var(--sw-border) 60%, transparent);
}

.pdf-ed__tb-group:last-child,
.pdf-ed__tb-group--end {
    border-right: none;
}

.pdf-ed__tb-group--end {
    margin-left: auto;
}

.pdf-ed__tb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-width: 32px;
    height: 32px;
    padding: 0 0.4rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--sw-text);
    font: inherit;
    font-size: 0.95rem;
    cursor: pointer;
}

.pdf-ed__tb-btn:hover {
    background: color-mix(in srgb, var(--sw-muted) 16%, transparent);
}

.pdf-ed__tb-btn.is-active,
.pdf-ed__tb-btn[aria-pressed="true"] {
    color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 14%, transparent);
    border-color: color-mix(in srgb, var(--primary-color) 35%, transparent);
}

.pdf-ed__tb-btn--danger:hover {
    color: #fff;
    background: #dc2626;
}

.pdf-ed__tb-btn:focus-visible,
.pdf-ed__tb-select:focus-visible,
.pdf-ed__input:focus-visible,
.pdf-ed__chip:focus-visible,
.pdf-ed__page-go:focus-visible,
.pdf-ed__page-act:focus-visible,
.pdf-ed__tab:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 1px;
}

.pdf-ed__tb-select {
    height: 32px;
    max-width: 9.5rem;
    padding: 0 0.4rem;
    border: 1px solid var(--sw-border);
    border-radius: 6px;
    background: var(--sw-surface);
    color: var(--sw-text);
    font: inherit;
    font-size: 0.85rem;
}

.pdf-ed__tb-select--narrow {
    width: 4rem;
}

/* Colour pickers: the letter shows the chosen colour as an underline swatch */
.pdf-ed__tb-color {
    flex-direction: column;
    font-weight: 700;
    line-height: 1;
}

.pdf-ed__tb-color input[type="color"] {
    width: 20px;
    height: 6px;
    padding: 0;
    margin-top: 2px;
    border: none;
    background: none;
    cursor: pointer;
}

.pdf-ed__tb-color input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.pdf-ed__tb-color input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.pdf-ed__tb-color--hl span {
    padding: 0 3px;
    border-radius: 2px;
    background: color-mix(in srgb, #fde047 55%, transparent);
}

/* Body: side panel + document viewport */
.pdf-ed__body {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    height: min(80vh, 900px);
    min-height: 520px;
}

.pdf-ed__side {
    overflow-y: auto;
    padding: 0.9rem;
    border-right: 1px solid var(--sw-border);
    background: var(--sw-surface);
}

.pdf-ed__panel + .pdf-ed__panel {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--sw-border);
}

.pdf-ed__panel-title {
    margin: 0 0 0.6rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sw-muted);
}

.pdf-ed__print {
    width: 100%;
}

.pdf-ed__hint {
    margin: 0.4rem 0 0.75rem;
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--sw-muted);
}

.pdf-ed__privacy {
    margin-top: 1.25rem;
}

.pdf-ed__btn-row {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}

.pdf-ed__btn-row > * {
    flex: 1;
    min-width: 0;
}

.pdf-ed__btn-row--wrap {
    flex-wrap: wrap;
}

.pdf-ed__small {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

.pdf-ed__label {
    display: block;
    margin: 0.7rem 0 0.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--sw-text);
}

.pdf-ed__input {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--sw-border);
    border-radius: 6px;
    background: var(--sw-surface);
    color: var(--sw-text);
    font: inherit;
    font-size: 0.9rem;
}

.pdf-ed__margins {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem 0.5rem;
    margin: 0;
    padding: 0;
    border: none;
}

.pdf-ed__margins legend {
    grid-column: 1 / -1;
    padding: 0;
}

.pdf-ed__margin {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.78rem;
    color: var(--sw-muted);
}

.pdf-ed__margin--inline {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.pdf-ed__check {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.8rem;
    font-size: 0.88rem;
    color: var(--sw-text);
    cursor: pointer;
}

.pdf-ed__check input {
    accent-color: var(--primary-color);
}

/* Pages list */
.pdf-ed__pages-list {
    list-style: none;
    margin: 0 0 0.6rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.pdf-ed__page-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.3rem 0.35rem;
    border: 1px solid var(--sw-border);
    border-radius: 6px;
}

.pdf-ed__page-item.is-warning {
    border-color: #f59e0b;
}

.pdf-ed__page-go {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 0.1rem 0.2rem;
    border: none;
    background: none;
    color: var(--sw-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.pdf-ed__page-go strong {
    font-size: 0.82rem;
}

.pdf-ed__page-go span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.75rem;
    color: var(--sw-muted);
}

.pdf-ed__page-actions {
    display: flex;
    gap: 1px;
}

.pdf-ed__page-act {
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--sw-muted);
    font-size: 0.8rem;
    cursor: pointer;
}

.pdf-ed__page-act:hover:not(:disabled) {
    color: var(--sw-text);
    background: color-mix(in srgb, var(--sw-muted) 18%, transparent);
}

.pdf-ed__page-act:disabled {
    opacity: 0.3;
    cursor: default;
}

.pdf-ed__add-page {
    width: 100%;
}

/* Document viewport */
.pdf-ed__viewport {
    overflow: auto;
    padding: 1.25rem 1rem;
    background: color-mix(in srgb, var(--sw-surface) 70%, #000 30%);
}

.pdf-ed__canvas {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    width: max-content;
    min-width: 100%;
    margin: 0 auto;
}

.pdf-ed__status {
    display: flex;
    gap: 1.25rem;
    padding: 0.4rem 0.9rem;
    border-top: 1px solid var(--sw-border);
    background: var(--sw-surface);
    font-size: 0.8rem;
    color: var(--sw-muted);
    font-variant-numeric: tabular-nums;
}

.pdf-ed__save-state {
    margin-left: auto;
}

.pdf-ed__save-state.is-error {
    color: #dc2626;
}

/* Floating image / table bars */
.pdf-ed__float {
    position: absolute;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.3rem 0.4rem;
    border: 1px solid var(--sw-border);
    border-radius: 8px;
    background: var(--sw-surface);
    box-shadow: var(--sw-shadow);
}

.pdf-ed__float[hidden] {
    display: none;
}

.pdf-ed__float-range {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.4rem;
    font-size: 0.78rem;
    color: var(--sw-muted);
}

.pdf-ed__float-range input {
    width: 90px;
    accent-color: var(--primary-color);
}

.pdf-ed__chip {
    padding: 0.25rem 0.55rem;
    border: 1px solid var(--sw-border);
    border-radius: 999px;
    background: var(--sw-surface);
    color: var(--sw-text);
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}

.pdf-ed__chip:hover {
    border-color: var(--primary-color);
}

.pdf-ed__chip--danger:hover {
    border-color: #dc2626;
    color: #dc2626;
}

/* Dialogs */
.pdf-ed__dialog {
    width: min(380px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--sw-border);
    border-radius: 12px;
    background: var(--sw-surface);
    color: var(--sw-text);
    box-shadow: var(--sw-shadow);
}

.pdf-ed__dialog--wide {
    width: min(620px, calc(100vw - 32px));
}

.pdf-ed__dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.pdf-ed__dialog-form {
    padding: 1.1rem 1.2rem;
}

.pdf-ed__dialog-title {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
    color: var(--sw-heading);
}

.pdf-ed__dialog-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1rem;
}

.pdf-ed__spacer {
    flex: 1;
}

.pdf-ed__find {
    position: fixed;
    top: 6rem;
    right: 1.5rem;
    left: auto;
    margin: 0;
    z-index: 1100;
    width: min(340px, calc(100vw - 32px));
}

.pdf-ed__table-grid {
    display: grid;
    grid-template-columns: repeat(8, 22px);
    gap: 3px;
    margin: 0.5rem 0 0.75rem;
}

.pdf-ed__table-grid span {
    width: 22px;
    height: 22px;
    border: 1px solid var(--sw-border);
    border-radius: 3px;
    cursor: pointer;
}

.pdf-ed__table-grid span.is-on {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 30%, transparent);
}

.pdf-ed__tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--sw-border);
}

.pdf-ed__tab {
    padding: 0.4rem 0.9rem;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--sw-muted);
    font: inherit;
    cursor: pointer;
}

.pdf-ed__tab.is-active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.pdf-ed__sig-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 560 / 200;
    border: 1px dashed var(--sw-border);
    border-radius: 8px;
    background: #fff;
    touch-action: none;
    cursor: crosshair;
}

.pdf-ed__sig-preview {
    min-height: 90px;
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: #fff;
    font-size: 2.6rem;
    line-height: 1.5;
    overflow: hidden;
    white-space: nowrap;
}

.pdf-ed__help-text {
    margin: 0 0 0.6rem;
    font-size: 0.92rem;
    line-height: 1.5;
}

.pdf-ed__keys {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.4rem;
    margin: 0;
}

.pdf-ed__keys div {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--sw-border);
    border-radius: 6px;
}

.pdf-ed__keys dt {
    font-size: 0.8rem;
}

.pdf-ed__keys dd {
    margin: 0.15rem 0 0;
    font-size: 0.85rem;
    color: var(--sw-muted);
}

.pdf-ed__keys kbd {
    padding: 0.05rem 0.35rem;
    border: 1px solid var(--sw-border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.75rem;
}

/* Focus mode: the editor fills the window */
.pdf-ed.pdf-ed--focus {
    position: fixed;
    inset: 0;
    z-index: 1000;
    border-radius: 0;
}

.pdf-ed--focus .pdf-ed__body {
    flex: 1;
    height: auto;
    min-height: 0;
}

html.pdf-ed-focus-lock {
    overflow: hidden;
}

/* ---------- Paper (shared by the editor and the print copy) ---------- */
.pdf-page {
    position: relative;
    flex: 0 0 auto;
    box-sizing: border-box;
    width: var(--page-w, 210mm);
    height: var(--page-h, 297mm);
    padding: var(--m-top, 20mm) var(--m-right, 20mm) var(--m-bottom, 20mm) var(--m-left, 20mm);
    background: #fff;
    color: #1a1a1a;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.pdf-page.is-overflowing {
    box-shadow: 0 0 0 3px #f59e0b, 0 2px 10px rgba(0, 0, 0, 0.35);
}

.pdf-page__body {
    height: 100%;
    overflow: hidden;
    outline: none;
    font-family: Georgia, serif;
    font-size: 11pt;
    line-height: 1.5;
    overflow-wrap: break-word;
    caret-color: #c0392b;
}

.pdf-page__body::after {
    content: '';
    display: block;
    clear: both;
}

.pdf-page__num {
    position: absolute;
    bottom: calc(var(--m-bottom, 20mm) / 2 - 0.5em);
    left: 0;
    right: 0;
    text-align: center;
    font-family: Georgia, serif;
    font-size: 9pt;
    color: #777;
}

.pdf-page__body > :first-child {
    margin-top: 0;
}

.pdf-page__body p {
    margin: 0 0 0.6em;
}

.pdf-page__body h1,
.pdf-page__body h2,
.pdf-page__body h3 {
    margin: 1em 0 0.4em;
    color: #111;
    line-height: 1.25;
    font-family: inherit;
}

.pdf-page__body h1 {
    font-size: 22pt;
}

.pdf-page__body h2 {
    font-size: 16pt;
}

.pdf-page__body h3 {
    font-size: 13pt;
}

.pdf-page__body blockquote {
    margin: 0.8em 0;
    padding: 0.2em 0 0.2em 1em;
    border-left: 3px solid #c0392b;
    color: #444;
    font-style: italic;
}

.pdf-page__body ul,
.pdf-page__body ol {
    margin: 0 0 0.6em;
    padding-left: 1.6em;
}

.pdf-page__body a {
    color: #1d4ed8;
}

.pdf-page__body hr {
    margin: 1em 0;
    border: none;
    border-top: 1px solid #bbb;
}

.pdf-table {
    width: 100%;
    margin: 0.4em 0 0.8em;
    border-collapse: collapse;
    font-size: 0.95em;
}

.pdf-table th,
.pdf-table td {
    padding: 0.35em 0.55em;
    border: 1px solid #c8c8c8;
    text-align: left;
    vertical-align: top;
}

.pdf-table th {
    background: #f1f1f1;
    font-weight: 700;
}

.pdf-img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0.4em auto 0.8em;
    cursor: pointer;
}

.pdf-img--left {
    margin-left: 0;
}

.pdf-img--right {
    margin-right: 0;
}

.pdf-img--wrap-left {
    float: left;
    margin: 0.2em 1em 0.6em 0;
}

.pdf-img--wrap-right {
    float: right;
    margin: 0.2em 0 0.6em 1em;
}

.pdf-img.is-selected {
    outline: 2px solid #c0392b;
    outline-offset: 2px;
}

.pdf-sig {
    margin-top: 0.2em;
    margin-bottom: 0.2em;
}

/* Table of contents */
.pdf-toc {
    position: relative;
    margin: 0 0 1.2em;
    padding: 0.8em 1em;
    border: 1px solid #e2e2e2;
    border-radius: 6px;
    background: #fafafa;
}

.pdf-toc__title {
    margin: 0 0 0.5em !important;
    font-size: 13pt;
    font-weight: 700;
}

.pdf-toc__item {
    display: flex;
    align-items: baseline;
    gap: 0.4em;
    margin: 0.15em 0 !important;
}

.pdf-toc__item a {
    color: inherit;
    text-decoration: none;
}

.pdf-toc__item--h1 {
    font-weight: 700;
}

.pdf-toc__item--h2 {
    padding-left: 1.2em;
}

.pdf-toc__item--h3 {
    padding-left: 2.4em;
    font-size: 0.95em;
}

.pdf-toc__dots {
    flex: 1;
    border-bottom: 1px dotted #999;
    transform: translateY(-0.25em);
}

.pdf-toc__refresh {
    position: absolute;
    top: 0.6em;
    right: 0.6em;
    padding: 0.15em 0.6em;
    border: 1px solid #c0392b;
    border-radius: 4px;
    background: #fff;
    color: #c0392b;
    font: inherit;
    font-size: 8pt;
    cursor: pointer;
}

.pdf-toc__empty {
    color: #777;
    font-style: italic;
}

::highlight(pdf-find) {
    background-color: #fde68a;
    color: #111;
}

::highlight(pdf-find-current) {
    background-color: #f97316;
    color: #fff;
}

/* Print copy: hidden on screen, the only thing printed */
#pdf-print-root {
    display: none;
}

@media print {
    .pdf-print .pdf-page {
        box-shadow: none;
        break-after: page;
        page-break-after: always;
    }

    .pdf-print .pdf-page:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    .pdf-print .pdf-page__body,
    .pdf-print .pdf-page__num {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

@media (max-width: 860px) {
    .pdf-ed__body {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(420px, 70vh) auto;
        height: auto;
    }

    .pdf-ed__viewport {
        grid-row: 1;
    }

    .pdf-ed__side {
        grid-row: 2;
        border-right: none;
        border-top: 1px solid var(--sw-border);
    }

    .pdf-ed__tb-group {
        border-right: none;
        padding-right: 0;
    }

    .pdf-ed__tb-group--end {
        margin-left: 0;
    }

    .pdf-ed--focus .pdf-ed__body {
        grid-template-rows: minmax(0, 1fr);
    }

    .pdf-ed--focus .pdf-ed__side {
        display: none;
    }
}
