/* PDF Editor — client-side interactive editor styles.
   Reuses color / radius / shadow custom properties defined in main.css (:root). */

.editor-app {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    min-height: 480px;
}

/* ---------- Drop zone (before a file is loaded) ---------- */
.editor-dropzone {
    padding: 56px 24px;
    text-align: center;
}
.editor-dropzone.dragover { border-color: var(--cherry); background: var(--cherry-light); }
.editor-dropzone-inner { max-width: 420px; margin: 0 auto; }

/* ---------- Loading state ---------- */
.editor-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 80px 24px;
    color: var(--text-muted);
}
.editor-spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--border);
    border-top-color: var(--cherry);
    border-radius: 50%;
    animation: editor-spin 0.8s linear infinite;
}
@keyframes editor-spin { to { transform: rotate(360deg); } }

/* ---------- Workspace shell: full-screen modal ---------- */
/* #editor-workspace is the fixed, full-viewport backdrop; #editor-workspace-panel is the
   actual popup "window" — sized well short of the viewport so the backdrop reads behind it. */
.editor-workspace {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(16, 16, 20, 0.65);
    padding: 2vh 2vw;
}
.editor-workspace[hidden] { display: none; }

.editor-workspace-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 96vw;
    height: 92vh;
    min-height: 420px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Body scroll lock while the modal is open — toggled on <body> from pdf-editor.js */
body.editor-modal-open { overflow: hidden; }

/* ---------- Top toolbar ---------- */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-subtle);
    flex-shrink: 0;
}
.editor-toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 6px;
    border-right: 1px solid var(--border);
}
.editor-toolbar-group:last-child { border-right: none; margin-left: auto; }
.editor-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.editor-btn svg { flex-shrink: 0; }
.editor-btn:hover:not(:disabled) { background: var(--surface); border-color: var(--border); }
.editor-btn.active { background: var(--cherry-light); border-color: var(--cherry); color: var(--cherry); }
.editor-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.editor-btn-wide { width: auto; padding: 0 12px; font-size: 0.85rem; font-weight: 600; }
.editor-btn-preview { border-color: var(--border); color: var(--text); }
.editor-btn-preview:hover:not(:disabled) { background: var(--surface); border-color: var(--cherry); color: var(--cherry); }
.editor-btn-download {
    background: linear-gradient(145deg, #ff6b81 0%, var(--cherry) 45%, var(--cherry-dark) 100%);
    color: #fff;
    border: none;
    font-weight: 700;
}
.editor-btn-download:hover:not(:disabled) { filter: brightness(1.05); color: var(--text); }
.editor-btn-close { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.editor-btn-close:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: #fff; }
.editor-zoom-label { font-size: 0.8rem; color: var(--text-muted); min-width: 42px; text-align: center; }
.editor-filename {
    font-size: 0.82rem;
    color: var(--text-muted);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Contextual sub-toolbar (font/color pickers etc) ---------- */
.editor-subtoolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    font-size: 0.82rem;
}
.editor-subtoolbar[hidden] { display: none; }
.editor-field {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
}
.editor-field select,
.editor-field input[type="number"] {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-subtle);
    color: var(--text);
    padding: 4px 6px;
    font-size: 0.82rem;
}
.editor-color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    padding: 0;
    background: none;
}
.editor-color-input { width: 28px; height: 28px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; }
.editor-sep { width: 1px; height: 20px; background: var(--border); }
.editor-field-label { color: var(--text-muted); }
.editor-field-value { color: var(--text-muted); min-width: 34px; text-align: right; }
.editor-zorder-btn { width: 30px; height: 30px; }

/* ---------- Quick-stamp dropdown ---------- */
.editor-toolbar-dropdown { position: relative; }
.editor-stamp-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 150px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}
.editor-stamp-menu[hidden] { display: none; }
.editor-stamp-option {
    padding: 7px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-weight: 700;
    font-size: 0.82rem;
    text-align: left;
    cursor: pointer;
}
.editor-stamp-option:hover { background: var(--bg-subtle); }

/* ---------- Main body: sidebar + canvas ---------- */
.editor-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* Page thumbnail sidebar */
.editor-sidebar {
    width: 168px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: var(--bg-subtle);
    overflow-y: auto;
    padding: 12px 10px;
}
.editor-page-thumb {
    position: relative;
    margin-bottom: 14px;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: grab;
    overflow: hidden;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.editor-page-thumb:active { cursor: grabbing; }
.editor-page-thumb.active { border-color: var(--cherry); box-shadow: var(--shadow-md); }
.editor-page-thumb.dragging { opacity: 0.4; }
.editor-page-thumb.drag-over-top { box-shadow: inset 0 3px 0 var(--cherry); }
.editor-page-thumb.drag-over-bottom { box-shadow: inset 0 -3px 0 var(--cherry); }
.editor-page-thumb canvas { display: block; width: 100%; height: auto; pointer-events: none; }
.editor-page-thumb-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
}
.editor-page-thumb-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.editor-page-thumb:hover .editor-page-thumb-actions { opacity: 1; }
.editor-page-thumb-action {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    cursor: pointer;
}
.editor-page-thumb-action:hover { background: var(--cherry); }

/* Canvas / page viewing area */
.editor-canvas-area {
    flex: 1;
    min-width: 0;
    overflow: auto;
    background: var(--bg-subtle);
    display: flex;
    justify-content: center;
    padding: 24px;
}
.editor-page-stage {
    position: relative;
    background: #fff;
    box-shadow: var(--shadow-lg);
    flex-shrink: 0;
    height: fit-content;
    touch-action: none;
}
.editor-page-canvas { display: block; }
.editor-annotation-layer {
    position: absolute;
    inset: 0;
    /* Individual annotation elements opt back into pointer-events */
    pointer-events: none;
}
.editor-page-stage.tool-active-placing { cursor: crosshair; }

/* ---------- Annotation elements ---------- */
.editor-annot {
    position: absolute;
    box-sizing: border-box;
    pointer-events: auto;
    cursor: move;
    border: 1px dashed transparent;
}
.editor-annot:hover { border-color: rgba(37, 99, 235, 0.5); }
.editor-annot.selected { border: 1px solid var(--blue-link); box-shadow: 0 0 0 1px var(--blue-link); }
.editor-annot-resize-handle {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--blue-link);
    border: 2px solid #fff;
    cursor: nwse-resize;
    display: none;
}
.editor-annot.selected .editor-annot-resize-handle { display: block; }
.editor-annot-delete-btn {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: 2px solid #fff;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 0;
}
.editor-annot.selected .editor-annot-delete-btn { display: flex; }

.editor-annot-textarea {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    resize: none;
    outline: none;
    overflow: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: Helvetica, Arial, sans-serif;
}
.editor-annot-image img { width: 100%; height: 100%; object-fit: fill; display: block; pointer-events: none; }
.editor-annot-whiteout { background: #ffffff; border: 1px dashed rgba(0, 0, 0, 0.15); }
.editor-annot-highlight { background: currentColor; opacity: 0.4; mix-blend-mode: multiply; }
/* underline/strikethrough accents are drawn as an SVG line in pdf-editor.js (rotation-aware —
   see underlineLocalPoints) rather than a fixed CSS border edge, which stays put regardless of
   page rotation. */
.editor-annot-shape-rect { border: 2px solid currentColor; background: transparent; }
.editor-annot-shape-ellipse { border: 2px solid currentColor; background: transparent; border-radius: 50%; }
.editor-annot-shape-line { background: transparent; }
.editor-annot-draw, .editor-annot-shape-line-svg { pointer-events: none; }
.editor-annot-draw svg, .editor-annot-shape-line svg { width: 100%; height: 100%; overflow: visible; }

/* Freehand drawing live-preview layer */
.editor-draw-preview {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* ---------- Signature panel ---------- */
.editor-signature-panel {
    position: absolute;
    z-index: 20;
    top: 60px;
    right: 20px;
    width: 340px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 16px;
}
.editor-signature-panel[hidden] { display: none; }
.editor-signature-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.editor-signature-tab {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border);
    background: var(--bg-subtle);
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted);
}
.editor-signature-tab.active { background: var(--cherry-light); border-color: var(--cherry); color: var(--cherry); }
.editor-signature-pad {
    width: 100%;
    height: 140px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    touch-action: none;
    cursor: crosshair;
}
.editor-signature-type-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    color: var(--text);
    font-size: 1.4rem;
    margin-bottom: 10px;
}
.editor-signature-type-preview {
    width: 100%;
    height: 100px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #16192b;
    overflow: hidden;
}
.editor-signature-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.editor-signature-pane[hidden] { display: none; }

/* ---------- Empty / error states ---------- */
.editor-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    z-index: 600; /* above the .editor-workspace modal backdrop (z-index: 500) */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.editor-toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.editor-toast.error { background: var(--danger); color: #fff; }

/* ---------- Draft resume banner ---------- */
.editor-draft-banner {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: 560px;
    margin: 0 auto;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.editor-draft-banner svg { flex-shrink: 0; color: var(--cherry); }
.editor-draft-banner-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.editor-draft-banner-text strong { font-size: 0.95rem; }
.editor-draft-banner-text span { font-size: 0.82rem; color: var(--text-muted); }
.editor-draft-banner-actions { display: flex; gap: 8px; flex-shrink: 0; }
.editor-draft-banner[hidden] { display: none; }

/* ---------- Leave-page confirmation modal ---------- */
.editor-leave-modal {
    position: fixed;
    inset: 0;
    z-index: 700; /* above the editor-workspace modal (500) and its toast (600) */
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(16, 16, 20, 0.65);
    padding: 20px;
}
.editor-leave-modal-panel {
    width: 100%;
    max-width: 420px;
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 24px;
}
.editor-leave-modal-panel h3 { margin: 0 0 10px; }
.editor-leave-modal-panel p { margin: 0 0 20px; color: var(--text-muted); font-size: 0.9rem; }
.editor-leave-modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.editor-leave-modal[hidden] { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .editor-workspace { padding: 0; }
    .editor-workspace-panel { width: 100vw; height: 100vh; border-radius: 0; }
    .editor-sidebar { width: 116px; }
    .editor-signature-panel { width: calc(100% - 40px); right: 20px; left: 20px; }
}
@media (max-width: 640px) {
    .editor-toolbar-group { padding: 0 3px; gap: 1px; }
    .editor-btn { width: 32px; height: 32px; }
    .editor-btn-wide { width: auto; height: 32px; padding: 0 10px; }
    .editor-filename { display: none; }
    .editor-sidebar { width: 88px; }
}
