* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f5f7fa;
    color: #333;
    min-height: 100vh;
    padding: 2rem;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2rem;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 1rem;
}

/* Tabs */
.tabs {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.tab {
    padding: 0.6rem 1.5rem;
    border: none;
    background: #e8e8e8;
    color: #666;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    transition: all 0.2s;
}

.tab:hover {
    background: #ddd;
}

.tab.active {
    background: white;
    color: #0066cc;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

/* Tool Panels */
.tool-panel {
    display: none;
}

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

.tool-description {
    text-align: center;
    color: #666;
    margin-bottom: 1.5rem;
}

.tool-instructions {
    background: #f0f7ff;
    border: 1px solid #d0e8f7;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: #444;
}

.tool-instructions p {
    margin: 0;
}

/* PDF Panels */
.pdf-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.pdf-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
}

.pdf-name {
    font-weight: 500;
    color: #444;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.panel-actions {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-small {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    background: #e8f4fc;
    color: #0066cc;
}

.btn-small:hover {
    background: #d0e8f7;
}

.btn-secondary {
    background: #f0f0f0;
    color: #666;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-primary {
    background: #0066cc;
    color: white;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-primary:hover:not(:disabled) {
    background: #0052a3;
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-large {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* Drop Zone */
.drop-zone {
    min-height: 250px;
    padding: 1.25rem;
    position: relative;
}

.drop-zone-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    color: #999;
    transition: all 0.2s;
}

.drop-zone-prompt svg {
    margin-bottom: 1rem;
    opacity: 0.5;
}

.drop-zone.dragover .drop-zone-prompt {
    border-color: #0066cc;
    background: #f0f7ff;
    color: #0066cc;
}

.drop-zone.has-pages .drop-zone-prompt {
    display: none;
}

/* Page Grid */
.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
}

.page-thumb {
    position: relative;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    background: white;
}

.page-thumb:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.page-thumb.selected {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

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

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

.page-thumb.selected .page-number {
    background: #0066cc;
}

.page-check {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: #0066cc;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
}

.page-thumb.selected .page-check {
    display: flex;
}

/* Output Section */
.output-section {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 1.25rem;
    margin-bottom: 2rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
}

.hint {
    font-size: 0.85rem;
    color: #999;
}

.output-queue {
    min-height: 140px;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px dashed #e0e0e0;
}

.queue-empty {
    width: 100%;
    text-align: center;
    color: #999;
    padding: 2rem;
}

.queue-item {
    position: relative;
    width: 100px;
    cursor: grab;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    background: white;
    transition: all 0.2s;
}

.queue-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.queue-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

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

.queue-item-label {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    text-align: center;
    padding: 0.25rem;
    font-size: 0.7rem;
    font-weight: 500;
}

.queue-item-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s;
}

.queue-item:hover .queue-item-remove {
    opacity: 1;
}

.queue-item-remove:hover {
    background: #cc0000;
}

/* Actions */
.actions {
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 1rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 12px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

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

.modal-title {
    font-weight: 600;
    color: #333;
}

.modal-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-indicator {
    font-size: 0.9rem;
    color: #666;
    min-width: 60px;
    text-align: center;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #999;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.modal-close:hover {
    background: #f0f0f0;
    color: #333;
}

.modal-body {
    padding: 1.5rem;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
}

.modal-body canvas {
    max-width: 100%;
    max-height: calc(90vh - 100px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}


/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #666;
}

.loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 3px solid #eee;
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 0.5rem;
}

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

/* Responsive */
@media (max-width: 900px) {
    .pdf-panels {
        grid-template-columns: 1fr;
    }

    body {
        padding: 1rem;
    }
}

@media (max-width: 600px) {
    .panel-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .pdf-name {
        max-width: 100%;
    }
}

/* Overlay Tool Styles */
.overlay-container {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2rem;
    align-items: flex-start;
}

.overlay-sidebar {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.overlay-source {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.overlay-source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    font-weight: 500;
    color: #444;
}

.overlay-source-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.layer-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.layer-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.drop-zone-small {
    min-height: 150px;
    padding: 1rem;
}

.drop-zone-small .drop-zone-prompt {
    min-height: 120px;
    font-size: 0.9rem;
}

.drop-zone-small .drop-zone-prompt svg {
    margin-bottom: 0.5rem;
}

.overlay-page-select {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.overlay-thumbs-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 100px;
}

.overlay-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #eee;
    margin-top: 0.25rem;
}

.overlay-pagination .page-info {
    font-size: 0.75rem;
    color: #666;
    min-width: 70px;
    text-align: center;
}

.overlay-pagination .btn {
    padding: 0.25rem 0.5rem;
    min-width: 28px;
}

.overlay-page-thumb {
    width: 80px;
    position: relative;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    border: 2px solid transparent;
}

.overlay-page-thumb:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.overlay-page-thumb.selected {
    border-color: #0066cc;
}

.overlay-page-thumb canvas {
    display: block;
    width: 100%;
}

.overlay-page-thumb .page-number {
    font-size: 0.65rem;
    padding: 0.2rem;
}

/* Overlay Main Area */
.overlay-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* Overlay Controls */
.overlay-controls {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 0.75rem 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: center;
}

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

.control-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #555;
    white-space: nowrap;
}

.control-group input[type="range"] {
    width: 80px;
    cursor: pointer;
}

.control-group > span:not(.layer-dot) {
    font-size: 0.75rem;
    color: #888;
    min-width: 35px;
}

.btn-group {
    display: flex;
    gap: 0.25rem;
}

.btn-group .btn {
    border-radius: 4px;
}

.btn-group .btn.active {
    background: #0066cc;
    color: white;
}

.btn-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.btn-group-vertical .btn {
    border-radius: 4px;
    width: 100%;
    justify-content: flex-start;
}

.btn-group-vertical .btn.active {
    background: #0066cc;
    color: white;
}

.overlay-workspace {
    flex: 1;
    min-height: 400px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border-radius: 12px;
}

.overlay-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #999;
    gap: 1rem;
    text-align: center;
}

.overlay-placeholder svg {
    opacity: 0.5;
}

.placeholder-steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.placeholder-steps p {
    margin: 0;
}

.placeholder-steps strong {
    color: #666;
}

.overlay-canvas-container {
    position: relative;
    display: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    max-width: 100%;
    max-height: 75vh;
}

.overlay-canvas-container.active {
    display: block;
    width: auto !important;
    height: auto !important;
}

.overlay-canvas-container canvas {
    position: absolute;
    top: 0;
    left: 0;
}

.overlay-canvas-container #composite-canvas {
    position: relative;
    cursor: crosshair;
    max-width: 100%;
    max-height: 75vh;
    width: auto;
    height: auto;
}

.overlay-canvas-container #bottom-canvas,
.overlay-canvas-container #top-canvas,
.overlay-canvas-container #mask-canvas {
    pointer-events: none;
    display: none;
}

/* Responsive for overlay */
@media (max-width: 900px) {
    .overlay-container {
        flex-direction: column;
    }

    .overlay-sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .overlay-sidebar .overlay-source {
        flex: 1;
        min-width: 200px;
    }

    .overlay-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .overlay-controls .control-group {
        flex-wrap: wrap;
    }
}

.btn-secondary.btn-large {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-secondary.btn-large:disabled {
    background: #e0e0e0;
    color: #999;
    cursor: not-allowed;
}
