:root {
    --editor-bg: #f5f5f7;
    --sidebar-bg: #ffffff;
    --toolbar-bg: #ffffff;
    --canvas-bg: #e8e8e8;
    --border-color: #e0e0e0;
    --primary-color: #E5322D;
    --primary-hover: #c92a26;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --tool-active-bg: #fef2f2;
    --tool-hover-bg: #f5f5f5;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] {
    --editor-bg: #1a1a1a;
    --sidebar-bg: #242424;
    --toolbar-bg: #242424;
    --canvas-bg: #2a2a2a;
    --border-color: #3a3a3a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --tool-active-bg: #3a2020;
    --tool-hover-bg: #333333;
}

* {
    box-sizing: border-box;
}

body.pdf-editor-page {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--editor-bg);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

.hidden-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.pdf-editor-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

.editor-sidebar {
    width: 120px;
    min-width: 120px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.sidebar-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.thumbnails-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.thumbnail-item {
    background: white;
    border: 2px solid transparent;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.thumbnail-item:hover {
    border-color: var(--primary-color);
    transform: scale(1.02);
}

.thumbnail-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(229, 50, 45, 0.2);
}

.thumbnail-canvas {
    width: 100%;
    height: auto;
    display: block;
}

.thumbnail-number {
    text-align: center;
    font-size: 11px;
    color: var(--text-secondary);
    padding: 4px 0;
    background: var(--sidebar-bg);
}

.editor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.editor-toolbar {
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mode-toggle {
    display: flex;
    background: var(--editor-bg);
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    color: var(--text-primary);
    background: var(--tool-hover-bg);
}

.mode-btn.active {
    background: var(--primary-color);
    color: white;
}

.mode-btn.active svg {
    stroke: white;
}

.pro-badge {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #1a1a1a;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 4px;
    margin-left: 4px;
}

.tool-group {
    display: flex;
    gap: 4px;
    background: var(--editor-bg);
    padding: 4px;
    border-radius: 8px;
}

.tool-btn {
    position: relative;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.tool-btn:hover {
    background: var(--tool-hover-bg);
    color: var(--text-primary);
}

.tool-btn.active {
    background: var(--tool-active-bg);
    color: var(--primary-color);
}

.tool-btn.active svg {
    stroke: var(--primary-color);
}

.tool-cursor {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 10px;
    font-weight: 600;
}

.color-picker-container {
    position: relative;
    width: 32px;
    height: 32px;
}

.color-picker {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.color-preview {
    display: block;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid var(--border-color);
    background: #E5322D;
    pointer-events: none;
}

.font-size-select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--toolbar-bg);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

.undo-btn,
.redo-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.undo-btn:hover,
.redo-btn:hover {
    background: var(--tool-hover-bg);
    color: var(--text-primary);
}

.undo-btn:disabled,
.redo-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.editor-title-bar {
    padding: 16px 24px;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border-color);
}

.editor-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px 0;
}

.editor-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
}

.pdf-viewer-container {
    flex: 1;
    background: var(--canvas-bg);
    overflow: auto;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.upload-box {
    background: var(--toolbar-bg);
    border: 2px dashed var(--border-color);
    border-radius: 16px;
    padding: 48px 64px;
    text-align: center;
    transition: all 0.3s ease;
}

.upload-box:hover {
    border-color: var(--primary-color);
}

.upload-box.dragover {
    border-color: var(--primary-color);
    background: var(--tool-active-bg);
}

.upload-icon {
    margin-bottom: 16px;
    color: var(--primary-color);
}

.upload-box h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.upload-box p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 24px 0;
}

.upload-btn-main {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 32px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-btn-main:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.pdf-canvas-wrapper {
    position: relative;
    box-shadow: var(--shadow-md);
    background: white;
}

#pdfCanvas {
    display: block;
}

#annotationCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto;
    cursor: crosshair;
}

.text-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    line-height: 1.0;
}

.text-layer.edit-mode {
    pointer-events: auto;
}

.text-layer span {
    position: absolute;
    white-space: pre;
    color: transparent;
    transform-origin: 0% 0%;
    cursor: text;
}

.text-layer.edit-mode span {
    cursor: pointer;
    background: transparent;
    transition: background 0.2s ease;
}

.text-layer.edit-mode span:hover {
    background: rgba(229, 50, 45, 0.15);
    border-radius: 2px;
}

.text-layer.edit-mode span.selected {
    background: rgba(229, 50, 45, 0.3);
    outline: 2px solid var(--primary-color);
    border-radius: 2px;
}

.text-layer span.edited {
    color: inherit;
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    border-bottom: 2px solid rgba(76, 175, 80, 0.6);
}

.text-layer.edit-mode span.edited {
    background: rgba(76, 175, 80, 0.1);
    border-bottom: 2px solid rgba(76, 175, 80, 0.6);
}

.text-layer.edit-mode span.edited:hover {
    background: rgba(76, 175, 80, 0.25);
}

.text-layer.edit-mode span.edited.selected {
    background: rgba(76, 175, 80, 0.35);
    outline: 2px solid #4CAF50;
}

.text-edit-overlay {
    position: absolute;
    background: white;
    border: 2px solid var(--primary-color);
    border-radius: 4px;
    padding: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 100;
}

.text-edit-overlay input {
    border: none;
    outline: none;
    font-family: inherit;
    background: transparent;
    min-width: 100px;
}

.editor-bottom-bar {
    background: var(--toolbar-bg);
    border-top: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.page-navigation {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: var(--toolbar-bg);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--tool-hover-bg);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--editor-bg);
    border-radius: 6px;
}

.page-input {
    width: 40px;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.page-input:focus {
    outline: none;
}

.page-separator {
    color: var(--text-secondary);
}

#totalPages {
    color: var(--text-secondary);
    font-size: 14px;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: var(--toolbar-bg);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: var(--tool-hover-bg);
    color: var(--text-primary);
}

.zoom-level {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.fit-btn,
.fullscreen-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: var(--toolbar-bg);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.fit-btn:hover,
.fullscreen-btn:hover {
    background: var(--tool-hover-bg);
    color: var(--text-primary);
}

.editor-action-panel {
    width: 200px;
    min-width: 200px;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 20px;
}

.edit-pdf-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, #ff9a9e 0%, #E5322D 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(229, 50, 45, 0.3);
}

.edit-pdf-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(229, 50, 45, 0.4);
}

.edit-pdf-action-btn:active {
    transform: translateY(0);
}

.text-input-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--toolbar-bg);
    border-radius: 12px;
    padding: 24px;
    width: 400px;
    max-width: 90%;
    box-shadow: var(--shadow-md);
}

.modal-content textarea {
    width: 100%;
    height: 120px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    background: var(--editor-bg);
    color: var(--text-primary);
}

.modal-content textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-buttons {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn.cancel {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.modal-btn.cancel:hover {
    background: var(--tool-hover-bg);
}

.modal-btn.confirm {
    background: var(--primary-color);
    border: none;
    color: white;
}

.modal-btn.confirm:hover {
    background: var(--primary-hover);
}

@media (max-width: 900px) {
    .editor-sidebar {
        width: 80px;
        min-width: 80px;
    }
    
    .editor-action-panel {
        width: 160px;
        min-width: 160px;
    }
    
    .toolbar-left,
    .toolbar-right {
        flex-wrap: wrap;
    }
    
    .mode-btn span:not(.pro-badge) {
        display: none;
    }
}

@media (max-width: 600px) {
    .pdf-editor-container {
        flex-direction: column;
    }
    
    .editor-sidebar {
        width: 100%;
        height: 80px;
        min-width: auto;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .thumbnails-container {
        flex-direction: row;
        overflow-x: auto;
        padding: 8px;
    }
    
    .thumbnail-item {
        width: 50px;
        flex-shrink: 0;
    }
    
    .editor-action-panel {
        width: 100%;
        min-width: auto;
        border-left: none;
        border-top: 1px solid var(--border-color);
        padding: 12px;
    }
    
    .edit-pdf-action-btn {
        padding: 12px 20px;
    }
}
