/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --warning-color: #f59e0b;

    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --transition: all 0.2s ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
    padding: 2rem 1rem;
    text-align: center;
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
}

.logo-text {
    font-size: 1.75rem;
    font-weight: 700;
}

.tagline {
    opacity: 0.9;
    font-size: 0.95rem;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition);
    white-space: nowrap;
}

.nav-tab svg {
    width: 20px;
    height: 20px;
}

.nav-tab:hover {
    background: var(--bg-color);
    color: var(--text-primary);
}

.nav-tab.active {
    background: var(--primary-light);
    color: var(--primary-color);
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Sections */
.section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.section-desc {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Tool Cards (Home) */
.tool-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.tool-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    box-shadow: var(--shadow-md);
}

.tool-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.tool-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 1rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-icon svg {
    width: 32px;
    height: 32px;
}

.merge-icon {
    background: linear-gradient(135deg, #fecaca, #fca5a5);
    color: #dc2626;
}

.split-icon {
    background: linear-gradient(135deg, #bfdbfe, #93c5fd);
    color: #2563eb;
}

.compress-icon {
    background: linear-gradient(135deg, #bbf7d0, #86efac);
    color: #16a34a;
}

.convert-icon {
    background: linear-gradient(135deg, #e9d5ff, #d8b4fe);
    color: #9333ea;
}

.reorganize-icon {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #d97706;
}

.scan-icon {
    background: linear-gradient(135deg, #ccfbf1, #99f6e4);
    color: #0d9488;
}

.tool-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.tool-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Features Highlight */
.features-highlight {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.feature {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.feature svg {
    width: 20px;
    height: 20px;
    color: var(--success-color);
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    background: var(--card-bg);
    transition: var(--transition);
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.drop-zone svg {
    width: 48px;
    height: 48px;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.drop-zone p {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.drop-zone span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 1rem;
}

.file-input-label {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.file-input-label:hover {
    background: var(--primary-hover);
}

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

.file-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
    cursor: grab;
    transition: var(--transition);
}

.file-item:hover {
    box-shadow: var(--shadow-md);
}

.file-item.dragging {
    opacity: 0.5;
    transform: scale(1.02);
}

.file-item.drag-over {
    border: 2px dashed var(--primary-color);
}

.file-icon {
    width: 40px;
    height: 40px;
    background: #fee2e2;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #dc2626;
    flex-shrink: 0;
}

.file-icon svg {
    width: 20px;
    height: 20px;
}

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

.file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.file-remove {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-remove:hover {
    background: #fee2e2;
    color: var(--error-color);
}

.file-remove svg {
    width: 18px;
    height: 18px;
}

/* Action Bar */
.action-bar {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn svg {
    width: 18px;
    height: 18px;
}

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

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

.btn-primary:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* Progress */
.progress-container {
    margin-top: 1.5rem;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), #8b5cf6);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    margin-top: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Split Options */
.split-options,
.compress-options,
.pdf-to-img-options {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.pdf-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.pdf-info-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    flex: 1;
}

.btn-preview {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-preview:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
}

.btn-preview svg {
    width: 16px;
    height: 16px;
}

.pdf-name {
    font-weight: 600;
    color: var(--text-primary);
}

.pdf-pages,
.pdf-size {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.split-mode {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.radio-label:hover {
    background: var(--bg-color);
}

.radio-label input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
}

.page-selection {
    margin-bottom: 1.5rem;
}

.page-selection label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.page-selection input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: var(--transition);
}

.page-selection input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Page Thumbnails */
.page-thumbnails {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.page-thumbnail {
    position: relative;
    aspect-ratio: 3/4;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    border: 2px solid transparent;
    transition: var(--transition);
}

.page-thumbnail:hover {
    box-shadow: var(--shadow-md);
}

.page-thumbnail.selected {
    border-color: var(--primary-color);
}

.page-thumbnail canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.page-number {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.25rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 0.75rem;
    text-align: center;
}

/* Quality Selector */
.quality-selector label {
    display: block;
    font-weight: 500;
    margin-bottom: 1rem;
}

.quality-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.quality-option {
    cursor: pointer;
}

.quality-option input {
    display: none;
}

.quality-card {
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    text-align: center;
    transition: var(--transition);
}

.quality-option input:checked + .quality-card {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.quality-card strong {
    display: block;
    margin-bottom: 0.25rem;
}

.quality-card span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Result Panel */
.result-panel {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 1.5rem;
    text-align: center;
}

.result-panel h3 {
    color: #166534;
    margin-bottom: 1rem;
}

.size-comparison {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.size-comparison svg {
    width: 24px;
    height: 24px;
    color: #166534;
}

.size-item {
    text-align: center;
}

.size-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.size-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.savings {
    color: #166534;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* Result Info */
.result-info {
    margin-bottom: 1rem;
}

.result-filename {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.result-meta {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Download Button */
.btn-download {
    margin-top: 0.5rem;
    padding: 0.875rem 2rem;
    font-size: 1rem;
}

.btn-download svg {
    width: 20px;
    height: 20px;
}

/* Convert Tabs */
.convert-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.convert-tab {
    flex: 1;
    padding: 1rem;
    border: 2px solid var(--border-color);
    background: var(--card-bg);
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.convert-tab:hover {
    border-color: var(--primary-color);
}

.convert-tab.active {
    border-color: var(--primary-color);
    background: var(--primary-light);
    color: var(--primary-color);
}

.convert-panel {
    display: none;
}

.convert-panel.active {
    display: block;
}

/* Image List */
.image-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.image-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    cursor: grab;
}

.image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    user-select: none;
    transition: transform 0.3s ease;
}

.image-order {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    pointer-events: none;
}

.image-item .remove-btn,
.image-item .rotate-btn {
    position: absolute;
    top: 0.5rem;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.image-item .remove-btn {
    right: 0.5rem;
}

.image-item .rotate-btn {
    right: 2rem;
}

.image-item .rotate-btn:hover {
    background: var(--primary-color);
}

.image-item:hover .remove-btn,
.image-item:hover .rotate-btn {
    opacity: 1;
}

.image-item .remove-btn svg,
.image-item .rotate-btn svg {
    width: 14px;
    height: 14px;
}

.image-item.dragging {
    opacity: 0.5;
    transform: scale(1.05);
    cursor: grabbing;
    z-index: 10;
    box-shadow: var(--shadow-lg);
}

.image-item:not(.dragging) {
    transition: transform 0.15s ease;
}

/* Format Selector */
.format-selector {
    margin-bottom: 1.5rem;
}

.format-selector > label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.format-options {
    display: flex;
    gap: 1rem;
}

.format-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.format-option input {
    accent-color: var(--primary-color);
}

/* Scale Selector */
.scale-selector {
    margin-bottom: 1rem;
}

.scale-selector label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.scale-selector input[type="range"] {
    width: 100%;
    accent-color: var(--primary-color);
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 350px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--error-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

.toast svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast.success svg {
    color: var(--success-color);
}

.toast.error svg {
    color: var(--error-color);
}

.toast.warning svg {
    color: var(--warning-color);
}

.toast-message {
    flex: 1;
    font-size: 0.9rem;
}

.toast-close {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-close:hover {
    background: var(--bg-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        padding: 1.5rem 1rem;
    }

    .logo-text {
        font-size: 1.5rem;
    }

    .nav-tabs {
        justify-content: flex-start;
        padding: 0.5rem;
    }

    .nav-tab {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .nav-tab span {
        display: none;
    }

    .main-content {
        padding: 1.5rem 1rem;
    }

    .tool-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .tool-card {
        padding: 1rem;
    }

    .tool-icon {
        width: 48px;
        height: 48px;
    }

    .tool-icon svg {
        width: 24px;
        height: 24px;
    }

    .features-highlight {
        flex-direction: column;
        gap: 1rem;
        align-items: center;
    }

    .drop-zone {
        padding: 2rem 1rem;
    }

    .quality-options {
        grid-template-columns: 1fr;
    }

    .action-bar {
        flex-direction: column;
    }

    .btn {
        justify-content: center;
    }

    .size-comparison {
        flex-direction: column;
        gap: 1rem;
    }

    .toast-container {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }

    .toast {
        max-width: none;
    }
}

@media (max-width: 480px) {
    .tool-cards {
        grid-template-columns: 1fr;
    }

    .convert-tabs {
        flex-direction: column;
    }

    .page-thumbnails {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
}

/* Loading State */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Drag handle for sortable items */
.drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    padding: 0.5rem;
}

.drag-handle:active {
    cursor: grabbing;
}

.drag-handle svg {
    width: 16px;
    height: 16px;
}

/* Reorganize Section */
.reorganize-workspace {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.reorganize-hint {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-align: center;
}

.reorganize-pages {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    min-height: 200px;
}

.reorganize-page {
    position: relative;
    aspect-ratio: 3/4;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    cursor: grab;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
    border: 2px solid transparent;
}

.reorganize-page:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.reorganize-page.dragging {
    opacity: 0.5;
    transform: scale(1.05);
    cursor: grabbing;
    z-index: 10;
}

.reorganize-page.drag-over {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.reorganize-page canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.reorganize-page-number {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
    text-align: center;
}

.reorganize-page-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: var(--primary-color);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.reorganize-page-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.reorganize-page:hover .reorganize-page-delete {
    opacity: 1;
}

.reorganize-page-delete:hover {
    background: #dc2626;
}

.reorganize-page-delete svg {
    width: 14px;
    height: 14px;
}

@media (max-width: 768px) {
    .reorganize-pages {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

/* Preview Button */
.file-preview {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-preview:hover {
    background: var(--primary-light);
    color: var(--primary-color);
}

.file-preview svg {
    width: 18px;
    height: 18px;
}

/* Offcanvas Panel */
.offcanvas-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.offcanvas-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.offcanvas {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 500px;
    background: var(--card-bg);
    z-index: 1200;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}

.offcanvas.active {
    transform: translateX(0);
}

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

.offcanvas-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 1rem;
}

.offcanvas-close {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.offcanvas-close:hover {
    background: var(--bg-color);
    color: var(--text-primary);
}

.offcanvas-close svg {
    width: 20px;
    height: 20px;
}

.offcanvas-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Preview Controls */
.preview-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
}

.preview-nav {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-nav:hover:not(:disabled) {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

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

.preview-nav svg {
    width: 18px;
    height: 18px;
}

.preview-page-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-width: 120px;
    text-align: center;
}

/* Preview Container */
.preview-container {
    flex: 1;
    overflow: auto;
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: var(--bg-color);
}

.preview-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.preview-loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

#preview-canvas {
    max-width: 100%;
    height: auto;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-sm);
    background: white;
}

#preview-canvas.hidden {
    display: none;
}

/* Responsive Offcanvas */
@media (max-width: 768px) {
    .offcanvas {
        max-width: 100%;
    }
}

/* Scan Section */
.scan-options {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

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

.option-group label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.option-group input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
}

.option-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.option-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.option-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.option-value {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: right;
}

.radio-group {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font-weight: normal;
    font-size: 0.9rem;
}

.radio-option input[type="radio"] {
    accent-color: var(--primary-color);
    width: 16px;
    height: 16px;
}

@media (max-width: 480px) {
    .options-grid {
        grid-template-columns: 1fr;
    }
}

/* Scan Workspace - Two Column Layout */
.scan-workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-top: 1.5rem;
}

.scan-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.scan-controls h4,
.scan-preview-pane h4 {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.scan-preview-pane {
    display: flex;
    flex-direction: column;
}

.scan-preview-container {
    position: relative;
    flex: 1;
    min-height: 300px;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#scan-preview-canvas {
    max-width: 100%;
    max-height: 400px;
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-sm);
}

.scan-preview-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    color: var(--text-secondary);
}

.scan-preview-loading.hidden {
    display: none;
}

@media (max-width: 768px) {
    .scan-workspace {
        grid-template-columns: 1fr;
    }

    .scan-preview-container {
        min-height: 250px;
    }
}

/* Sign Section */
.sign-workspace {
    margin-top: 1.5rem;
}

.sign-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}

.sign-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.sign-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
}

.sign-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.signature-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--primary-light);
    color: var(--primary-color);
    border: 2px dashed var(--primary-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    width: 100%;
}

.signature-upload-btn:hover {
    background: var(--primary-color);
    color: white;
}

.signature-upload-btn svg {
    width: 18px;
    height: 18px;
}

.current-signature {
    position: relative;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.current-signature img {
    width: 100%;
    max-height: 80px;
    object-fit: contain;
}

.signature-remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0.8;
    transition: var(--transition);
}

.signature-remove-btn:hover {
    opacity: 1;
}

.signature-remove-btn svg {
    width: 14px;
    height: 14px;
}

.saved-signatures {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.no-signatures {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 0.5rem;
}

.saved-signature-item {
    position: relative;
    width: 60px;
    height: 45px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
}

.saved-signature-item:hover {
    border-color: var(--primary-color);
}

.saved-sig-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
    background: white;
}

.saved-sig-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
}

.saved-signature-item:hover .saved-sig-remove {
    opacity: 1;
}

.saved-sig-remove svg {
    width: 12px;
    height: 12px;
}

.placement-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.placement-options .radio-label {
    padding: 0.5rem;
    font-size: 0.875rem;
}

.page-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.page-nav-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.page-nav-btn:hover:not(:disabled) {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

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

.page-nav-btn svg {
    width: 18px;
    height: 18px;
}

.page-indicator {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.size-slider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.size-slider input[type="range"] {
    flex: 1;
}

.size-value {
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 50px;
}

.signature-buttons {
    display: flex;
    gap: 0.5rem;
}

.signature-buttons .signature-upload-btn {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.75rem;
}

.signature-draw-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--card-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: var(--transition);
}

.signature-draw-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.signature-draw-btn svg {
    width: 16px;
    height: 16px;
}

.sign-main-area {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sign-pages-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
}

.sign-pages-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.pages-hint {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.sign-page-thumbnails {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    max-height: 200px;
    overflow-y: auto;
    padding: 0.25rem;
}

.loading-thumbnails {
    text-align: center;
    color: var(--text-secondary);
    padding: 1rem;
    font-size: 0.875rem;
}

.sign-thumb-item {
    position: relative;
    width: 80px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    background: white;
}

.sign-thumb-item:hover {
    border-color: var(--primary-color);
}

.sign-thumb-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.sign-thumb-item img {
    width: 100%;
    display: block;
}

.sign-thumb-checkbox {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 5;
}

.sign-thumb-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.sign-thumb-checkbox label {
    display: none;
}

.sign-thumb-number {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 0.625rem;
    padding: 2px 6px;
    border-radius: 3px;
}

.sign-canvas-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.canvas-wrapper {
    position: relative;
    display: inline-block;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    max-width: 100%;
}

.canvas-wrapper.enlarged {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-wrapper canvas {
    display: block;
    max-width: 100%;
    box-shadow: var(--shadow-md);
}

.signature-draggable {
    position: absolute;
    cursor: grab;
    border: 2px dashed var(--primary-color);
    border-radius: 4px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.9);
    z-index: 10;
    user-select: none;
}

.signature-draggable img {
    display: block;
    pointer-events: none;
    user-select: none;
}

.signature-draggable:active {
    cursor: grabbing;
}

.canvas-hint {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Draw Signature Modal */
.draw-signature-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: 1000;
    padding: 1rem;
}

.draw-signature-content {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    max-width: 550px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}

.draw-signature-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.draw-signature-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

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

.modal-close-btn svg {
    width: 20px;
    height: 20px;
}

.draw-signature-body {
    padding: 1.25rem;
}

.draw-signature-body canvas {
    width: 100%;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: crosshair;
    touch-action: none;
}

.draw-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.draw-signature-options {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem 1rem;
    flex-wrap: wrap;
}

.draw-signature-options label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.color-options {
    display: flex;
    gap: 0.5rem;
}

.color-btn {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.color-btn:hover,
.color-btn.active {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

.draw-signature-options input[type="range"] {
    width: 80px;
}

.draw-signature-actions {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    justify-content: flex-end;
}

.sign-icon {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

@media (max-width: 900px) {
    .sign-layout {
        grid-template-columns: 1fr;
    }

    .sign-sidebar {
        order: 2;
    }

    .sign-main-area {
        order: 1;
    }
}

@media (max-width: 480px) {
    .saved-signature-item {
        width: 50px;
        height: 38px;
    }

    .sign-thumb-item {
        width: 60px;
    }

    .signature-buttons {
        flex-direction: column;
    }

    .draw-signature-options {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Text Box Styles */
.text-hint {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.7rem;
}

.text-box-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.text-box-controls input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    transition: var(--transition);
}

.text-box-controls input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.text-box-options {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.text-color-picker,
.text-size-picker {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.text-color-picker input[type="color"] {
    width: 28px;
    height: 24px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
}

.text-size-picker select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
}

.page-text-boxes {
    margin-top: 0.75rem;
    max-height: 120px;
    overflow-y: auto;
}

.no-text-boxes {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 0.5rem;
}

.text-box-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.5rem;
    background: var(--bg-color);
    border-radius: var(--radius-sm);
    margin-bottom: 0.35rem;
}

.text-box-preview {
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

.text-box-remove {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    flex-shrink: 0;
}

.text-box-remove:hover {
    background: var(--error-color);
    color: white;
}

.text-box-remove svg {
    width: 14px;
    height: 14px;
}

/* Draggable text boxes on canvas */
.text-boxes-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 5;
}

.draggable-text-box {
    position: absolute;
    cursor: grab;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.85);
    border: 1px dashed var(--primary-color);
    border-radius: 3px;
    pointer-events: auto;
    user-select: none;
    white-space: nowrap;
    transition: box-shadow 0.15s ease;
}

.draggable-text-box:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.draggable-text-box.dragging {
    cursor: grabbing;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 20;
}

.text-box-delete {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.draggable-text-box:hover .text-box-delete {
    opacity: 1;
}
