/* ============================================
   ByteNChill - Tools CSS
   Shared styles for all tool pages
   ============================================ */

/* ---- Upload Zone ---- */
.upload-zone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    padding: 2.5rem 2rem;
    border: 2px dashed #cbd5e1;
    border-radius: 1.25rem;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: hidden;
}

.dark .upload-zone {
    border-color: #334155;
    background: #0f172a;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: #f59e0b;
    background: #fffbeb;
}

.dark .upload-zone:hover,
.dark .upload-zone.drag-over {
    border-color: #f59e0b;
    background: rgba(245, 158, 11, 0.05);
}

.upload-zone.drag-over .upload-content { opacity: 0.3; }
.upload-zone.drag-over .upload-hover-overlay { opacity: 1; }

.upload-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    transition: opacity 0.2s;
    pointer-events: none;
}

.upload-icon {
    color: #94a3b8;
}

.dark .upload-icon {
    color: #475569;
}

.upload-zone:hover .upload-icon {
    color: #f59e0b;
}

.upload-label {
    font-size: 1rem;
    font-weight: 600;
    color: #334155;
}

.dark .upload-label {
    color: #e2e8f0;
}

.upload-sublabel {
    font-size: 0.8125rem;
    color: #94a3b8;
}

.upload-hover-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: #f59e0b;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

/* ---- File List ---- */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
}

.dark .file-item {
    background: #1e293b;
    border-color: #334155;
}

.file-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.5rem;
    background: #e0f2fe;
    color: #0284c7;
    flex-shrink: 0;
}

.dark .file-item-icon {
    background: rgba(2, 132, 199, 0.15);
}

.file-item-info {
    flex: 1;
    min-width: 0;
}

.file-item-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dark .file-item-name {
    color: #f1f5f9;
}

.file-item-size {
    font-size: 0.75rem;
    color: #94a3b8;
}

.file-item-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.375rem;
    color: #94a3b8;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}

.file-item-remove:hover {
    color: #ef4444;
    background: #fef2f2;
}

.dark .file-item-remove:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ---- Progress Bar ---- */
.progress-container {
    margin-top: 1.5rem;
}

.progress-bar {
    width: 100%;
    height: 0.5rem;
    border-radius: 9999px;
    background: #e2e8f0;
    overflow: hidden;
}

.dark .progress-bar {
    background: #1e293b;
}

.progress-fill {
    height: 100%;
    border-radius: 9999px;
    background: linear-gradient(90deg, #f59e0b, #f97316);
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.8125rem;
    color: #64748b;
    margin-top: 0.5rem;
    text-align: center;
}

/* ---- Tool Workspace ---- */
.tool-workspace {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 1.25rem;
    padding: 2rem;
}

.dark .tool-workspace {
    background: #0f172a;
    border-color: #1e293b;
}

/* ---- Tool Results ---- */
.tool-results {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 1.25rem;
    padding: 2rem;
}

.dark .tool-results {
    background: #0f172a;
    border-color: #1e293b;
}

/* ---- Action Button ---- */
.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 2rem;
    border-radius: 0.75rem;
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tool-btn-primary {
    background: linear-gradient(135deg, #f59e0b, #f97316);
    color: white;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.tool-btn-primary:hover:not(:disabled) {
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4);
    transform: translateY(-1px);
}

.tool-btn-secondary {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
}

.dark .tool-btn-secondary {
    background: #1e293b;
    color: #e2e8f0;
    border-color: #334155;
}

.tool-btn-secondary:hover:not(:disabled) {
    background: #e2e8f0;
}

.dark .tool-btn-secondary:hover:not(:disabled) {
    background: #334155;
}

.tool-btn-success {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

.tool-btn-outline {
    background: transparent;
    color: #f59e0b;
    border: 2px solid #f59e0b;
}

.tool-btn-outline:hover:not(:disabled) {
    background: #f59e0b;
    color: white;
}

.dark .tool-btn-outline {
    color: #fbbf24;
    border-color: #fbbf24;
}

.dark .tool-btn-outline:hover:not(:disabled) {
    background: #fbbf24;
    color: #0f172a;
}

/* ---- My Documents Picker Button ---- */
.mydocs-picker-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #f59e0b;
    background: transparent;
    border: 1.5px solid #f59e0b;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    z-index: 3;
    pointer-events: auto;
}

.mydocs-picker-btn:hover {
    background: #f59e0b;
    color: white;
}

.dark .mydocs-picker-btn {
    color: #fbbf24;
    border-color: #fbbf24;
}

.dark .mydocs-picker-btn:hover {
    background: #fbbf24;
    color: #0f172a;
}

/* ---- Document Picker Modal ---- */
.doc-picker-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.doc-picker-modal {
    background: white;
    border-radius: 1rem;
    width: 100%;
    max-width: 540px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.dark .doc-picker-modal {
    background: #1e293b;
}

.doc-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e2e8f0;
}

.dark .doc-picker-header {
    border-color: #334155;
}

.doc-picker-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #0f172a;
}

.dark .doc-picker-header h3 {
    color: #f1f5f9;
}

.doc-picker-close {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    border-radius: 0.375rem;
    transition: all 0.15s;
}

.doc-picker-close:hover {
    background: #f1f5f9;
    color: #ef4444;
}

.dark .doc-picker-close:hover {
    background: #334155;
}

.doc-picker-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.doc-picker-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.doc-picker-item:hover {
    background: #f8fafc;
}

.dark .doc-picker-item:hover {
    background: #0f172a;
}

.doc-picker-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.5rem;
    background: #fef2f2;
    color: #ef4444;
    flex-shrink: 0;
}

.dark .doc-picker-item-icon {
    background: rgba(239, 68, 68, 0.15);
}

.doc-picker-item-info {
    flex: 1;
    min-width: 0;
}

.doc-picker-item-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dark .doc-picker-item-name {
    color: #f1f5f9;
}

.doc-picker-item-meta {
    font-size: 0.6875rem;
    color: #94a3b8;
    margin-top: 1px;
}

.doc-picker-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: #94a3b8;
    font-size: 0.875rem;
}

.doc-picker-loading {
    text-align: center;
    padding: 2rem;
    color: #94a3b8;
    font-size: 0.875rem;
}

/* ---- Thumbnail Grid ---- */
.thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.thumbnail-item {
    position: relative;
    border-radius: 0.75rem;
    border: 2px solid #e2e8f0;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.dark .thumbnail-item {
    border-color: #334155;
    background: #1e293b;
}

.thumbnail-item:hover {
    border-color: #f59e0b;
}

.thumbnail-item.selected {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.thumbnail-canvas-wrap {
    aspect-ratio: 3/4;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.dark .thumbnail-canvas-wrap {
    background: #0f172a;
}

.thumbnail-canvas-wrap canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.thumbnail-label {
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: #64748b;
    text-align: center;
    border-top: 1px solid #e2e8f0;
}

.dark .thumbnail-label {
    color: #94a3b8;
    border-color: #334155;
}

.thumbnail-badge {
    position: absolute;
    top: 0.375rem;
    right: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 9999px;
    background: #f59e0b;
    color: white;
    font-size: 0.625rem;
    font-weight: 700;
}

/* ---- Options Panel ---- */
.tool-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.25rem;
    margin-top: 1.5rem;
    border-radius: 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.dark .tool-options {
    background: #1e293b;
    border-color: #334155;
}

.tool-option-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.tool-option-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dark .tool-option-label {
    color: #94a3b8;
}

.tool-select,
.tool-input {
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
    background: white;
    color: #0f172a;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s;
}

.dark .tool-select,
.dark .tool-input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}

.tool-select:focus,
.tool-input:focus {
    border-color: #f59e0b;
}

/* ---- Download Section ---- */
.download-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    text-align: center;
}

.download-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    border-radius: 1rem;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(22, 163, 74, 0.1));
    color: #22c55e;
}

.download-filename {
    font-size: 1rem;
    font-weight: 600;
    color: #0f172a;
}

.dark .download-filename {
    color: #f1f5f9;
}

.download-size {
    font-size: 0.8125rem;
    color: #94a3b8;
}

/* ---- Signature Canvas ---- */
.signature-canvas-container {
    position: relative;
    border: 2px solid #e2e8f0;
    border-radius: 0.75rem;
    overflow: hidden;
    background: white;
}

.dark .signature-canvas-container {
    border-color: #334155;
    background: #1e293b;
}

.signature-canvas {
    display: block;
    width: 100%;
    cursor: crosshair;
}

/* ---- Loading Spinner ---- */
.tool-spinner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: tool-spin 0.6s linear infinite;
}

@keyframes tool-spin {
    to { transform: rotate(360deg); }
}

/* ---- PDF Preview ---- */
.pdf-preview-container {
    width: 100%;
    max-height: 600px;
    overflow: auto;
    border-radius: 0.75rem;
    border: 1px solid #e2e8f0;
    background: #64748b;
}

.dark .pdf-preview-container {
    border-color: #334155;
}

.pdf-preview-container canvas {
    display: block;
    margin: 1rem auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ---- Text Output ---- */
.text-output {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    color: #0f172a;
    resize: vertical;
}

.dark .text-output {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
}

/* ---- Result Image ---- */
.result-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: repeating-conic-gradient(#e2e8f0 0% 25%, transparent 0% 50%) 50% / 20px 20px;
    border-radius: 0.75rem;
    border: 1px solid #e2e8f0;
}

.dark .result-image-container {
    background: repeating-conic-gradient(#334155 0% 25%, #1e293b 0% 50%) 50% / 20px 20px;
    border-color: #334155;
}

.result-image-container img {
    max-width: 100%;
    max-height: 500px;
    border-radius: 0.5rem;
}

/* ---- Sortable Ghost ---- */
.sortable-ghost {
    opacity: 0.4;
}

.sortable-chosen {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* ---- Rotation Controls ---- */
.rotation-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.375rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 0.5rem;
}

.dark .rotation-controls {
    background: rgba(255, 255, 255, 0.05);
}

.rotation-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border: none;
    border-radius: 0.375rem;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.8125rem;
}

.rotation-btn:hover {
    background: white;
    color: #0f172a;
}

.dark .rotation-btn:hover {
    background: #334155;
    color: #f1f5f9;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .upload-zone {
        min-height: 200px;
        padding: 1.5rem 1rem;
    }

    .tool-workspace {
        padding: 1.25rem;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }

    .tool-options {
        flex-direction: column;
    }

    .tool-btn {
        width: 100%;
    }
}

/* ============================================
   PDF Editor - Full Professional Layout
   ============================================ */

/* --- Editor Shell (fixed fullscreen overlay) --- */
.pdf-editor {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: none;
    flex-direction: column;
    background: #f1f5f9;
    overflow: hidden;
}
.pdf-editor.active {
    display: flex;
}
.dark .pdf-editor { background: #0f172a; }

/* Lock body scroll when editor open */
body.pe-editor-open {
    overflow: hidden !important;
    height: 100vh !important;
}

/* Tab bar for multiple PDFs */
.pe-tab-bar {
    display: flex;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
    height: 38px;
    padding: 0 0.25rem;
    gap: 0;
}
.dark .pe-tab-bar { background: #1e293b; border-color: #334155; }

.pe-tabs-scroll {
    display: flex;
    align-items: flex-end;
    overflow-x: auto;
    flex: 1;
    height: 100%;
    gap: 2px;
    padding: 0 0.25rem;
    scrollbar-width: none;
}
.pe-tabs-scroll::-webkit-scrollbar { display: none; }

.pe-tab {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    font-size: 0.7rem;
    font-weight: 500;
    color: #64748b;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    max-width: 180px;
    height: 100%;
    transition: all 0.15s;
}
.pe-tab:hover { color: #1e293b; background: #f8fafc; }
.dark .pe-tab:hover { color: #e2e8f0; background: rgba(255,255,255,0.05); }
.pe-tab.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
    background: #eff6ff;
}
.dark .pe-tab.active { color: #60a5fa; background: rgba(59,130,246,0.1); }
.pe-tab-icon { width: 14px; height: 14px; flex-shrink: 0; opacity: 0.7; }
.pe-tab .pe-tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.pe-tab .pe-tab-close {
    width: 16px; height: 16px; flex-shrink: 0;
    border: none; background: none; color: inherit;
    cursor: pointer; padding: 0; border-radius: 3px;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.15s;
}
.pe-tab:hover .pe-tab-close, .pe-tab.active .pe-tab-close { opacity: 0.6; }
.pe-tab .pe-tab-close:hover { opacity: 1; background: rgba(0,0,0,0.1); }
.pe-tab .pe-tab-close svg { width: 12px; height: 12px; }

.pe-tab-add {
    width: 26px; height: 26px;
    display: flex; align-items: center; justify-content: center;
    border: 1px dashed #cbd5e1; background: transparent;
    border-radius: 5px; cursor: pointer; color: #94a3b8;
    flex-shrink: 0; margin: 0 0.375rem; transition: all 0.15s;
}
.pe-tab-add:hover { border-color: #3b82f6; color: #3b82f6; background: #eff6ff; }
.dark .pe-tab-add { border-color: #475569; color: #64748b; }
.dark .pe-tab-add:hover { border-color: #60a5fa; color: #60a5fa; background: rgba(59,130,246,0.1); }
.pe-tab-add svg { width: 14px; height: 14px; }

.pe-file-close {
    width: 2rem; height: 2rem;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent; color: #94a3b8;
    cursor: pointer; border-radius: 0.375rem; transition: all 0.15s;
    flex-shrink: 0;
}
.pe-file-close:hover { background: #fef2f2; color: #ef4444; }
.dark .pe-file-close:hover { background: rgba(239,68,68,0.1); }
.pe-file-close svg { width: 1.25rem; height: 1.25rem; }

/* Thumbnail page actions (copy/paste) */
.pe-thumb-actions {
    display: flex; gap: 2px; margin-top: 3px; justify-content: center;
}
.pe-thumb-action {
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: rgba(0,0,0,0.05); color: #64748b;
    border-radius: 4px; cursor: pointer; padding: 0; transition: all 0.15s;
}
.pe-thumb-action:hover { background: #3b82f6; color: #fff; }
.pe-thumb-action svg { width: 12px; height: 12px; }
.pe-thumb-action.pe-paste-page { background: rgba(59,130,246,0.1); color: #3b82f6; }
.pe-thumb-action.pe-paste-page:hover { background: #3b82f6; color: #fff; }

/* --- Top Toolbar --- */
.pe-toolbar {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    z-index: 20;
    flex-shrink: 0;
}
.dark .pe-toolbar { background: #1e293b; border-color: #334155; }

.pe-toolbar-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.75rem;
    flex-wrap: wrap;
}

.pe-toolbar-row + .pe-toolbar-row {
    border-top: 1px solid #f1f5f9;
}
.dark .pe-toolbar-row + .pe-toolbar-row { border-color: #0f172a; }

/* Mode toggle pill */
.pe-mode-toggle {
    display: inline-flex;
    border-radius: 9999px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    margin-right: 0.5rem;
    flex-shrink: 0;
}
.dark .pe-mode-toggle { border-color: #475569; }

.pe-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: transparent;
    color: #64748b;
    transition: all 0.15s;
    white-space: nowrap;
}
.pe-mode-btn.active {
    background: #3b82f6;
    color: #fff;
}
.pe-mode-btn:not(.active):hover { background: #f1f5f9; }
.dark .pe-mode-btn:not(.active):hover { background: #334155; }
.dark .pe-mode-btn { color: #94a3b8; }

/* Toolbar icon buttons */
.pe-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    position: relative;
}
.pe-tool-btn:hover { background: #f1f5f9; color: #0f172a; }
.dark .pe-tool-btn { color: #94a3b8; }
.dark .pe-tool-btn:hover { background: #334155; color: #f1f5f9; }
.pe-tool-btn.active { background: #eff6ff; color: #3b82f6; }
.dark .pe-tool-btn.active { background: rgba(59,130,246,0.15); color: #60a5fa; }
.pe-tool-btn svg { width: 1rem; height: 1rem; }

/* Separator */
.pe-sep {
    width: 1px;
    height: 1.5rem;
    background: #e2e8f0;
    margin: 0 0.25rem;
    flex-shrink: 0;
}
.dark .pe-sep { background: #334155; }

/* Category tabs */
.pe-cat-tabs {
    display: flex;
    gap: 0.125rem;
    margin-left: 0.25rem;
}

.pe-cat-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.375rem;
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.pe-cat-tab:hover { background: #f1f5f9; color: #0f172a; }
.dark .pe-cat-tab { color: #94a3b8; }
.dark .pe-cat-tab:hover { background: #334155; color: #f1f5f9; }
.pe-cat-tab.active { background: #eff6ff; color: #3b82f6; font-weight: 600; }
.dark .pe-cat-tab.active { background: rgba(59,130,246,0.15); color: #60a5fa; }
.pe-cat-tab svg { width: 0.875rem; height: 0.875rem; }

/* Sub-tools row */
.pe-subtools {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.75rem;
    min-height: 2.5rem;
    border-top: 1px solid #f1f5f9;
    overflow-x: auto;
}
.dark .pe-subtools { border-color: #0f172a; }
.pe-subtools:empty { display: none; }

.pe-subtool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.pe-subtool-btn:hover { background: #f1f5f9; color: #0f172a; }
.dark .pe-subtool-btn { color: #94a3b8; }
.dark .pe-subtool-btn:hover { background: #334155; color: #f1f5f9; }
.pe-subtool-btn.active {
    background: #eff6ff;
    color: #3b82f6;
    border-color: #bfdbfe;
}
.dark .pe-subtool-btn.active {
    background: rgba(59,130,246,0.15);
    color: #60a5fa;
    border-color: rgba(59,130,246,0.3);
}
.pe-subtool-btn svg { width: 0.875rem; height: 0.875rem; }

/* Inline color picker in toolbar */
.pe-color-input {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: 2px solid #e2e8f0;
    cursor: pointer;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    background: none;
}
.pe-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.pe-color-input::-webkit-color-swatch { border: none; border-radius: 50%; }
.dark .pe-color-input { border-color: #475569; }

/* --- 3-Column Body (MUST be row) --- */
.pe-body {
    display: flex;
    flex-direction: row;
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}

/* --- Left Sidebar --- */
.pe-left {
    width: 200px;
    min-width: 200px;
    max-width: 200px;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    z-index: 10;
    flex-shrink: 0;
    position: relative;
    overflow: visible;
}
.dark .pe-left { background: #1e293b; border-color: #334155; }

.pe-left-tabs {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.dark .pe-left-tabs { border-color: #334155; }

.pe-left-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}
.pe-left-tab:hover { color: #3b82f6; background: #f8fafc; }
.dark .pe-left-tab:hover { background: #0f172a; }
.pe-left-tab.active { color: #3b82f6; }
.pe-left-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: #3b82f6;
    border-radius: 2px;
}
.pe-left-tab svg { width: 1.125rem; height: 1.125rem; }

/* Left sidebar views */
.pe-left-view {
    flex: 1;
    overflow-y: auto;
    display: none;
    padding: 0.5rem;
}
.pe-left-view.active { display: flex; flex-direction: column; }

/* Thumb zoom slider */
.pe-thumb-zoom {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.5rem;
    flex-shrink: 0;
}
.pe-thumb-zoom input[type=range] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #e2e8f0;
    border-radius: 2px;
    outline: none;
}
.dark .pe-thumb-zoom input[type=range] { background: #334155; }
.pe-thumb-zoom input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
}
.pe-thumb-zoom button {
    width: 1.25rem;
    height: 1.25rem;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Thumbnail items in sidebar */
.pe-thumb-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem;
}
.pe-thumb-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.375rem;
    border-radius: 0.5rem;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
}
.pe-thumb-item:hover { background: #f8fafc; }
.dark .pe-thumb-item:hover { background: #0f172a; }
.pe-thumb-item.active { border-color: #3b82f6; background: #eff6ff; }
.dark .pe-thumb-item.active { border-color: #3b82f6; background: rgba(59,130,246,0.1); }
.pe-thumb-item[draggable="true"] { cursor: grab; }
.pe-thumb-item.dragging { opacity: 0.35; cursor: grabbing; }
.pe-thumb-item.drag-over-top { border-top: 3px solid #3b82f6; border-radius: 3px 3px 0.5rem 0.5rem; }
.pe-thumb-item.drag-over-bottom { border-bottom: 3px solid #3b82f6; border-radius: 0.5rem 0.5rem 3px 3px; }
.pe-thumb-item canvas {
    max-width: 100%;
    border-radius: 0.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.pe-thumb-label {
    font-size: 0.6875rem;
    color: #64748b;
    margin-top: 0.25rem;
}
.dark .pe-thumb-label { color: #94a3b8; }

/* Outline / bookmark items */
.pe-outline-item, .pe-bookmark-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    color: #334155;
    cursor: pointer;
    transition: all 0.15s;
}
.pe-outline-item:hover, .pe-bookmark-item:hover { background: #f1f5f9; }
.dark .pe-outline-item, .dark .pe-bookmark-item { color: #e2e8f0; }
.dark .pe-outline-item:hover, .dark .pe-bookmark-item:hover { background: #0f172a; }

.pe-outline-item .indent { width: 1rem; flex-shrink: 0; }

.pe-bookmark-remove {
    margin-left: auto;
    width: 1.25rem;
    height: 1.25rem;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.75rem;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pe-bookmark-remove:hover { color: #ef4444; background: #fef2f2; }
.dark .pe-bookmark-remove:hover { background: rgba(239,68,68,0.1); }

/* Bookmark add button */
.pe-bookmark-add {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem;
    margin: 0.5rem 0;
    border: 1px dashed #cbd5e1;
    border-radius: 0.375rem;
    background: transparent;
    color: #64748b;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
}
.pe-bookmark-add:hover { border-color: #3b82f6; color: #3b82f6; }
.dark .pe-bookmark-add { border-color: #475569; color: #94a3b8; }

/* More menu dropdown - positioned relative to left sidebar */
.pe-more-menu {
    position: absolute;
    left: 0.5rem;
    top: 2.5rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 0.25rem;
    z-index: 999;
    min-width: 180px;
    display: none;
}
.dark .pe-more-menu { background: #1e293b; border-color: #334155; }
.pe-more-menu.open { display: block; }
.pe-more-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    color: #334155;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    transition: all 0.15s;
}
.pe-more-item:hover { background: #f1f5f9; }
.dark .pe-more-item { color: #e2e8f0; }
.dark .pe-more-item:hover { background: #0f172a; }

.pe-empty-msg {
    text-align: center;
    padding: 2rem 1rem;
    font-size: 0.75rem;
    color: #94a3b8;
}

/* --- Canvas Area (center - takes all remaining space) --- */
.pe-canvas-area {
    flex: 1 1 0%;
    min-width: 0;
    overflow: auto;
    background: #dde3ea;
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1.5rem;
}
.dark .pe-canvas-area { background: #0c1222; }

.pe-page-wrapper {
    position: relative;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    background: #fff;
    flex-shrink: 0;
}
.pe-page-wrapper canvas { display: block; }

/* Annotation overlay */
.pe-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
}

/* Drawing canvas overlay */
.pe-draw-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 6;
    cursor: crosshair;
}

/* --- Annotation objects on overlay --- */
.pe-annotation {
    position: absolute;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
}
.pe-annotation.selected {
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
}

/* Resize handles */
.pe-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #fff;
    border: 2px solid #3b82f6;
    border-radius: 2px;
    z-index: 10;
}
.pe-handle.nw { top: -4px; left: -4px; cursor: nw-resize; }
.pe-handle.ne { top: -4px; right: -4px; cursor: ne-resize; }
.pe-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.pe-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }
.pe-handle.n { top: -4px; left: 50%; margin-left: -4px; cursor: n-resize; }
.pe-handle.s { bottom: -4px; left: 50%; margin-left: -4px; cursor: s-resize; }
.pe-handle.w { top: 50%; left: -4px; margin-top: -4px; cursor: w-resize; }
.pe-handle.e { top: 50%; right: -4px; margin-top: -4px; cursor: e-resize; }

/* Text annotation editable */
.pe-text-box {
    min-width: 40px;
    min-height: 20px;
    padding: 2px 4px;
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
}

/* PDF text layer items (editable existing text) */
.pe-text-layer-item {
    box-sizing: border-box;
}
.pe-text-layer-item[contenteditable="true"] {
    background: rgba(255,255,255,0.95) !important;
    color: #000 !important;
    border-color: #3b82f6 !important;
    outline: 2px solid #3b82f6;
    outline-offset: 1px;
    box-shadow: 0 2px 8px rgba(59,130,246,0.2);
    z-index: 20 !important;
    padding: 1px 2px !important;
}

/* Zoom hint in canvas area */
.pe-zoom-hint {
    position: absolute;
    bottom: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.375rem 0.75rem;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 0.6875rem;
    border-radius: 9999px;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.3s;
}
.pe-zoom-hint.show { opacity: 1; }

/* Shape annotations */
.pe-shape { pointer-events: all; }
.pe-shape svg { width: 100%; height: 100%; }

/* Highlight / markup */
.pe-highlight { pointer-events: all; border-radius: 2px; }
.pe-sticky-note {
    width: 24px;
    height: 24px;
    font-size: 18px;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

/* Stamp */
.pe-stamp {
    padding: 0.25rem 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    border: 2px solid currentColor;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    letter-spacing: 0.05em;
    transform: rotate(-15deg);
    opacity: 0.8;
}

/* Form field overlays */
.pe-form-field {
    border: 1px dashed #3b82f6;
    background: rgba(59,130,246,0.05);
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: #3b82f6;
}

/* --- Right Sidebar --- */
.pe-right {
    width: 240px;
    min-width: 240px;
    max-width: 240px;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-left: 1px solid #e2e8f0;
    z-index: 10;
    flex-shrink: 0;
    flex-grow: 0;
    overflow-y: auto;
}
.dark .pe-right { background: #1e293b; border-color: #334155; }

.pe-right-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #0f172a;
    padding: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
}
.dark .pe-right-title { color: #f1f5f9; border-color: #0f172a; }

.pe-prop-group {
    padding: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
}
.dark .pe-prop-group { border-color: #0f172a; }

.pe-prop-label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.375rem;
}

.pe-prop-row {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.375rem;
}

.pe-prop-input {
    width: 100%;
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    background: #f8fafc;
    color: #0f172a;
    outline: none;
    transition: border-color 0.15s;
}
.pe-prop-input:focus { border-color: #3b82f6; }
.dark .pe-prop-input { background: #0f172a; border-color: #334155; color: #f1f5f9; }

.pe-prop-select {
    width: 100%;
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    background: #f8fafc;
    color: #0f172a;
    outline: none;
    cursor: pointer;
}
.dark .pe-prop-select { background: #0f172a; border-color: #334155; color: #f1f5f9; }

/* Style buttons (B I U) */
.pe-style-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    border: 1px solid #e2e8f0;
    background: transparent;
    color: #334155;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8125rem;
    transition: all 0.15s;
}
.pe-style-btn:hover { background: #f1f5f9; }
.dark .pe-style-btn { border-color: #334155; color: #e2e8f0; }
.dark .pe-style-btn:hover { background: #334155; }
.pe-style-btn.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }

/* Alignment buttons */
.pe-align-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    border: 1px solid #e2e8f0;
    background: transparent;
    color: #334155;
    cursor: pointer;
    transition: all 0.15s;
}
.pe-align-btn:hover { background: #f1f5f9; }
.dark .pe-align-btn { border-color: #334155; color: #e2e8f0; }
.pe-align-btn.active { background: #eff6ff; color: #3b82f6; border-color: #bfdbfe; }
.dark .pe-align-btn.active { background: rgba(59,130,246,0.15); }
.pe-align-btn svg { width: 0.875rem; height: 0.875rem; }

/* Opacity / width sliders in properties */
.pe-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #e2e8f0;
    border-radius: 2px;
    outline: none;
}
.dark .pe-slider { background: #334155; }
.pe-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* --- Bottom Navigation Bar --- */
.pe-bottombar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #1e293b;
    color: #e2e8f0;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.pe-bottombar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    border-radius: 0.25rem;
    transition: all 0.15s;
    font-size: 0.875rem;
}
.pe-bottombar button:hover { background: #334155; color: #f1f5f9; }
.pe-bottombar button:disabled { opacity: 0.3; cursor: not-allowed; }
.pe-bottombar button.active { background: #334155; color: #60a5fa; }

.pe-page-input {
    width: 2.5rem;
    text-align: center;
    padding: 0.25rem;
    font-size: 0.8125rem;
    background: #334155;
    border: 1px solid #475569;
    border-radius: 0.25rem;
    color: #f1f5f9;
    outline: none;
}
.pe-page-input:focus { border-color: #60a5fa; }

.pe-bottom-sep {
    width: 1px;
    height: 1.25rem;
    background: #475569;
    margin: 0 0.25rem;
}

.pe-bottom-label {
    font-size: 0.75rem;
    color: #94a3b8;
    white-space: nowrap;
}

.pe-zoom-display {
    font-size: 0.75rem;
    color: #e2e8f0;
    min-width: 2.5rem;
    text-align: center;
    cursor: pointer;
}
.pe-zoom-display:hover { color: #60a5fa; }

/* --- Floating Save Button --- */
.pe-save-btn {
    position: absolute;
    bottom: 4rem;
    right: 1.5rem;
    z-index: 30;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #f59e0b, #f97316);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(245,158,11,0.4);
    transition: all 0.2s;
}
.pe-save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(245,158,11,0.5);
}
.pe-save-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.pe-save-btn svg { width: 1.125rem; height: 1.125rem; }

/* Search overlay */
.pe-search-bar {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    display: none;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 25;
}
.dark .pe-search-bar { background: #1e293b; border-color: #334155; }
.pe-search-bar.open { display: flex; }
.pe-search-bar input {
    width: 180px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.25rem;
    background: #f8fafc;
    color: #0f172a;
    outline: none;
}
.dark .pe-search-bar input { background: #0f172a; border-color: #334155; color: #f1f5f9; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .pe-right { display: none; }
    .pe-left { width: 160px; min-width: 160px; }
}
@media (max-width: 768px) {
    .pe-left { display: none; }
    .pe-cat-tab span { display: none; }
    .pe-toolbar-row { gap: 0.125rem; padding: 0.25rem 0.5rem; }
    .pe-bottombar { gap: 0.25rem; padding: 0.375rem 0.5rem; }
    .pe-save-btn { bottom: 3.5rem; right: 0.75rem; padding: 0.5rem 1rem; font-size: 0.75rem; }
    .pe-tab-bar { height: 34px; }
    .pe-tab { font-size: 0.65rem; padding: 0.25rem 0.5rem; }
}
