/**
 * PDF Editor - Custom Styles
 */

/* Tab Navigation */
.tabs-nav {
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border-color, #e5e7eb);
    margin-bottom: 2rem;
    overflow-x: auto;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-secondary, #6b7280);
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--primary-color, #3b82f6);
    background: var(--bg-secondary, #f9fafb);
}

.tab-btn.active {
    color: var(--primary-color, #3b82f6);
    border-bottom-color: var(--primary-color, #3b82f6);
    font-weight: 600;
}

.tab-icon {
    font-size: 1.25rem;
}

.tab-label {
    font-size: 0.95rem;
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Usage Indicator */
.usage-indicator {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary, #f9fafb);
    border-radius: 8px;
    justify-content: center;
}

.usage-badge {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
}

.usage-badge.success {
    background: #d1fae5;
    color: #065f46;
}

.usage-badge.warning {
    background: #fef3c7;
    color: #92400e;
}

.usage-badge.danger {
    background: #fee2e2;
    color: #991b1b;
}

.usage-badge.premium {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.upgrade-link {
    color: var(--primary-color, #3b82f6);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}

.upgrade-link:hover {
    text-decoration: underline;
}

/* File List */
.file-list {
    margin-top: 1.5rem;
}

.file-list-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary, #1f2937);
}

.file-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    transition: all 0.2s;
}

.file-item:hover {
    background: var(--bg-tertiary, #f3f4f6);
    border-color: var(--primary-color, #3b82f6);
}

.file-icon {
    font-size: 1.5rem;
}

.file-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary, #1f2937);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    color: var(--text-secondary, #6b7280);
    font-size: 0.9rem;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 1.25rem;
    transition: color 0.2s;
}

.btn-icon:hover {
    color: var(--danger-color, #ef4444);
}

/* Operation Options */
.operation-options {
    margin-top: 1rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    color: white;
    font-size: 1.1rem;
    margin-top: 1rem;
    font-weight: 500;
}

/* Results Area */
.success-message {
    text-align: center;
    padding: 2rem;
    background: var(--bg-secondary, #f9fafb);
    border-radius: 8px;
    margin-bottom: 2rem;
}

.success-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.success-message h3 {
    color: var(--text-primary, #1f2937);
    font-size: 1.5rem;
    margin: 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    text-align: center;
    padding: 1.5rem;
    background: var(--bg-secondary, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color, #3b82f6);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-secondary, #6b7280);
    font-weight: 500;
}

.download-section {
    margin-top: 2rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-primary, #1f2937);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg-secondary, #f9fafb);
    color: var(--text-primary, #1f2937);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body p {
    margin-bottom: 1rem;
    color: var(--text-secondary, #6b7280);
}

.modal-body ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.modal-body li {
    margin-bottom: 0.5rem;
    color: var(--text-secondary, #6b7280);
}

/* Drag and Drop States */
.upload-area.drag-over {
    border-color: var(--primary-color, #3b82f6);
    background: var(--bg-secondary, #f9fafb);
}

/* Responsive Design */
@media (max-width: 768px) {
    .tabs-nav {
        gap: 0.25rem;
    }

    .tab-btn {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .tab-icon {
        font-size: 1rem;
    }

    .tab-label {
        display: none;
    }

    .tab-btn.active .tab-label {
        display: inline;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .file-item {
        flex-wrap: wrap;
    }

    .file-name {
        flex-basis: 100%;
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 480px) {
    .usage-indicator {
        flex-direction: column;
        gap: 0.5rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .tab-btn {
        color: #9ca3af;
    }

    .tab-btn:hover {
        color: #60a5fa;
        background: #1f2937;
    }

    .tab-btn.active {
        color: #60a5fa;
        border-bottom-color: #60a5fa;
    }

    .usage-indicator {
        background: #1f2937;
    }

    .file-item {
        background: #1f2937;
        border-color: #374151;
    }

    .file-item:hover {
        background: #111827;
        border-color: #60a5fa;
    }

    .file-name {
        color: #f9fafb;
    }

    .success-message {
        background: #1f2937;
    }

    .success-message h3 {
        color: #f9fafb;
    }

    .stat-card {
        background: #1f2937;
        border-color: #374151;
    }

    .stat-value {
        color: #60a5fa;
    }

    .modal-content {
        background: #1f2937;
    }

    .modal-header {
        border-bottom-color: #374151;
    }

    .modal-header h3 {
        color: #f9fafb;
    }

    .modal-close:hover {
        background: #111827;
    }
}

/* Fix: Enable pointer events on browse buttons (parent has pointer-events: none) */
#mergeBrowseBtn,
#splitBrowseBtn,
#compressBrowseBtn,
#pageManagerBrowseBtn {
    pointer-events: auto;
    cursor: pointer;
}

/* Formatting checkbox labels */
label input[type="checkbox"] {
    margin-right: 4px;
}

/* Text alignment select */
.form-select {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

/* Resize handles for image overlays */
.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #007bff;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
}

.resize-handle[data-position="nw"] {
    top: -6px;
    left: -6px;
    cursor: nwse-resize;
}

.resize-handle[data-position="ne"] {
    top: -6px;
    right: -6px;
    cursor: nesw-resize;
}

.resize-handle[data-position="se"] {
    bottom: -6px;
    right: -6px;
    cursor: nwse-resize;
}

.resize-handle[data-position="sw"] {
    bottom: -6px;
    left: -6px;
    cursor: nesw-resize;
}

/* Modern PDF Editor Styles */
.pdf-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

/* Advanced Modern Toolbar */
.pdf-modern-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.page-number-input {
    width: 60px;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
}

.page-separator {
    font-size: 14px;
    color: var(--color-text-secondary, #6b7280);
}

.scale-select {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 4px;
    background: white;
    font-size: 14px;
    min-width: 100px;
}

/* Tools Toolbar */
.pdf-tools-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.tool-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.tool-btn:hover {
    background: var(--color-bg-secondary, #f3f4f6);
    border-color: var(--color-primary, #3b82f6);
}

.tool-btn.active {
    background: var(--color-primary, #3b82f6);
    color: white;
    border-color: var(--color-primary, #3b82f6);
}

.tool-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Text Format Toolbar */
.text-format-toolbar {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.format-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.format-select {
    padding: 6px 10px;
    border: 1px solid var(--color-border, #ddd);
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    background: white;
}

.format-select:focus {
    outline: 2px solid var(--color-primary, #3b82f6);
    outline-offset: 1px;
}

.format-btn {
    padding: 6px 12px;
    min-width: 36px;
    border: 1px solid var(--color-border, #ddd);
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s;
}

.format-btn:hover {
    background: var(--color-bg-secondary, #f3f4f6);
    border-color: var(--color-primary, #3b82f6);
}

.format-btn.active {
    background: var(--color-primary, #3b82f6);
    color: white;
    border-color: var(--color-primary, #3b82f6);
}

.format-color {
    cursor: pointer;
}

/* Find Bar */
.find-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.find-input {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 4px;
    font-size: 14px;
}

.find-matches {
    font-size: 14px;
    color: var(--color-text-secondary, #6b7280);
    padding: 0 0.5rem;
}

.toolbar-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.page-indicator,
.zoom-indicator {
    padding: 0.5rem 1rem;
    background: var(--color-bg-secondary, #f3f4f6);
    border-radius: 6px;
    font-weight: 500;
    min-width: 120px;
    text-align: center;
}

.pdf-canvas-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
    background: #525659;
    border-radius: 0;
    overflow: auto;
    min-height: calc(100vh - 400px);
    position: relative;
}

#modernPdfCanvas {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    background: white;
    max-width: 100%;
    height: auto;
    position: relative;
    z-index: 1;  /* Canvas at base layer */
}

/* Annotation Overlay Canvas */
#annotationCanvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    cursor: crosshair;
}

.pdf-canvas-container.hand-tool #annotationCanvas {
    cursor: grab;
}

.pdf-canvas-container.hand-tool.dragging #annotationCanvas {
    cursor: grabbing;
}

/* Text Layer for Selection */
.textLayer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1.0;
    white-space: pre;
    cursor: text;
    user-select: text;
    z-index: 2;  /* Text layer above canvas */
    pointer-events: none;  /* Don't block clicks when visible */
}

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

.textLayer ::selection {
    background: rgba(0, 100, 200, 0.3);
}

/* Responsive Design for Modern Editor */
@media (max-width: 768px) {
    .pdf-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group {
        justify-content: center;
    }

    .pdf-canvas-container {
        padding: 1rem;
    }
}

/* Modern PDF Editor - DOM-Based Annotations */

/* Annotation Container */
#annotationContainer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: auto;  /* Enable clicks on container */
    z-index: 100;  /* Annotations above text layer */
    /* Dimensions set via JavaScript to match canvas */
    touch-action: none;  /* ✅ Prevent browser touch interference */
}

/* Annotation Elements */
.annotation-element {
    position: absolute;
    pointer-events: auto;
    cursor: move;
    box-sizing: border-box;
    z-index: 10;  /* Base z-index for all annotations */
    touch-action: none;  /* ✅ Allow custom drag handling */
}

.annotation-element.selected {
    outline: 2px solid #007bff;
    outline-offset: 2px;
    z-index: 1000;
}

.annotation-text {
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    padding: 8px 12px;
    min-width: 50px;
    min-height: 30px;
    background: transparent;  /* ✅ FIXED: Transparent background */
    border: none;  /* ✅ FIXED: No border */
}

.annotation-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    /* ❌ REMOVED: -webkit-user-drag: none; (was blocking dragging) */
    pointer-events: auto;  /* ✅ Allow clicking on images */
}

.annotation-highlight {
    background: rgba(255, 255, 0, 0.4);
    border: 1px dashed rgba(255, 200, 0, 0.6);
}

.annotation-preview {
    opacity: 0.6;
    border: 2px dashed rgba(0, 123, 255, 0.8);
}

.annotation-drawing {
    overflow: visible;
}

.annotation-shape {
    box-sizing: border-box;
}

/* Resize Handles (overriding previous styles) */
.annotation-element .resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 2px solid #007bff;
    border-radius: 50%;
    pointer-events: auto;
    z-index: 20;  /* Handles above annotation element */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.annotation-element .resize-handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.annotation-element .resize-handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.annotation-element .resize-handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.annotation-element .resize-handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.annotation-element .resize-handle.n {
    top: -5px;
    left: 50%;
    margin-left: -5px;
    cursor: n-resize;
}

.annotation-element .resize-handle.e {
    top: 50%;
    right: -5px;
    margin-top: -5px;
    cursor: e-resize;
}

.annotation-element .resize-handle.s {
    bottom: -5px;
    left: 50%;
    margin-left: -5px;
    cursor: s-resize;
}

.annotation-element .resize-handle.w {
    top: 50%;
    left: -5px;
    margin-top: -5px;
    cursor: w-resize;
}


/* Upload Zone Drag-Over State */
#viewerUploadZone.dragover {
    border-color: #5568d3;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    transform: scale(1.02);
}

/* Official PDF.js Viewer Container */
#officialViewerContainer {
    width: 100%;
    min-height: 600px;
}
