.hero:has(.editor-workspace:not([hidden])) {
    grid-template-columns: 1fr;
}

.editor-workspace {
    display: grid;
    gap: 12px;
}

.editor-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
}

.tool-button {
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--foreground);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

.tool-button:hover:not(:disabled) {
    background: var(--muted);
}

.tool-button[aria-pressed="true"] {
    border-color: var(--primary);
    background: var(--accent);
    color: var(--primary);
    font-weight: 700;
}

.tool-button:disabled,
.button:disabled,
.icon-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.color-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

.color-field input {
    width: 36px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: none;
}

.zoom-value {
    min-width: 56px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.option-hint {
    margin: 0;
    color: var(--muted-foreground);
    font-size: 13px;
}

.editor-pages,
.reader-pages {
    display: grid;
    justify-items: center;
    gap: 16px;
    max-height: 80vh;
    padding: 16px 0;
    overflow: auto;
    border-radius: 12px;
    background: var(--muted);
}

.editor-page {
    position: relative;
    flex: none;
    background: var(--color-document-paper);
    box-shadow: var(--shadow-md);
}

.editor-page canvas {
    display: block;
}

.editor-page .page-number {
    position: absolute;
    right: 8px;
    bottom: -22px;
    color: var(--muted-foreground);
    font-size: 12px;
}

.edit-layer {
    position: absolute;
    inset: 0;
    touch-action: none;
}

[data-tool="text"] .edit-layer {
    cursor: text;
}

[data-tool="highlight"] .edit-layer,
[data-tool="whiteout"] .edit-layer,
[data-tool="redact"] .edit-layer,
[data-tool="draw"] .edit-layer,
[data-tool="image"] .edit-layer,
[data-tool="signature"] .edit-layer {
    cursor: crosshair;
}

.existing-text {
    position: absolute;
    display: none;
    padding: 0;
    border: 0;
    border-radius: 2px;
    background: transparent;
    outline: 1px dashed color-mix(in srgb, var(--color-accent) 35%, transparent);
    cursor: text;
}

[data-tool="text"] .existing-text:not([hidden]) {
    display: block;
}

.existing-text:hover,
.existing-text:focus-visible {
    background: color-mix(in srgb, var(--color-accent) 14%, transparent);
    outline: 1px solid var(--color-accent);
}

.edit-item {
    position: absolute;
    outline: 1px dashed transparent;
    cursor: move;
    touch-action: none;
}

.edit-item:hover,
.edit-item:focus-within {
    outline-color: var(--color-accent);
}

.edit-text {
    min-width: 24px;
    cursor: default;
}

.text-content {
    min-width: 2ch;
    white-space: pre;
    line-height: 1.25;
    font-family: "Noto Sans", Inter, system-ui, sans-serif;
    outline: none;
    cursor: text;
}

.text-content:empty::before {
    content: attr(data-placeholder);
    opacity: 0.45;
}

.move-grip {
    position: absolute;
    top: -2px;
    left: -18px;
    color: var(--color-accent);
    font-size: 14px;
    line-height: 1;
    cursor: move;
    opacity: 0;
}

.edit-item:hover .move-grip,
.edit-item:focus-within .move-grip {
    opacity: 1;
}

.edit-image img {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.edit-highlight {
    background: var(--color-document-highlight);
    mix-blend-mode: multiply;
}

.edit-whiteout {
    background: var(--color-document-paper);
    outline-color: var(--color-document-edge);
}

.edit-redact {
    background: var(--color-document-redact);
}

.edit-draw {
    cursor: move;
}

.edit-draw svg {
    display: block;
    overflow: visible;
    pointer-events: none;
}

.resize-handle {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 12px;
    height: 12px;
    border: 2px solid var(--color-surface);
    border-radius: 50%;
    background: var(--color-accent);
    cursor: nwse-resize;
    opacity: 0;
}

.remove-item {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--color-danger);
    color: var(--color-surface);
    font: 700 14px/22px system-ui, sans-serif;
    cursor: pointer;
    opacity: 0;
}

.edit-item:hover > .resize-handle,
.edit-item:hover > .remove-item,
.edit-item:focus-within > .resize-handle,
.edit-item:focus-within > .remove-item {
    opacity: 1;
}

@media (hover: none) {
    .resize-handle,
    .remove-item,
    .move-grip {
        opacity: 1;
    }
}

.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.page-card {
    display: grid;
    justify-items: center;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    cursor: grab;
}

.page-card.is-dragging {
    opacity: 0.4;
}

.page-card.is-deleted .thumb-frame {
    opacity: 0.25;
}

.page-card.is-deleted .page-number {
    text-decoration: line-through;
}

.thumb-frame {
    display: grid;
    place-items: center;
    width: 160px;
    height: 200px;
}

.thumb {
    max-width: 100%;
    max-height: 100%;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s;
}

.page-number {
    color: var(--muted-foreground);
    font-size: 13px;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
}

.icon-button {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--foreground);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.icon-button:hover {
    background: var(--muted);
}

.icon-button[aria-pressed="true"] {
    border-color: var(--danger);
    color: var(--danger);
}

.pages-input {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--foreground);
    font: inherit;
}

.form-fields {
    display: grid;
    gap: 12px;
}

.form-field {
    display: grid;
    gap: 4px;
    font-size: 14px;
    font-weight: 600;
}

.check-field {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.check-field .pages-input {
    width: auto;
    min-height: 0;
}

.signature-dialog {
    width: min(640px, calc(100vw - 32px));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--foreground);
}

.signature-dialog::backdrop {
    background: var(--color-overlay);
}

.signature-dialog form {
    display: grid;
    gap: 12px;
}

.signature-dialog h2 {
    margin: 0;
    font-size: 20px;
}

.signature-pad {
    width: 100%;
    aspect-ratio: 3 / 1;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: var(--color-document-paper);
    touch-action: none;
}
