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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 12px;
}

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

.header {
    text-align: center;
    color: white;
    padding: 16px 0;
    margin-bottom: 20px;
}

.header h1 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
}

.header p {
    font-size: 14px;
    opacity: 0.9;
}

/* PDF Upload Section */
.pdf-upload-section {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.pdf-upload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
}

.pdf-status {
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
}

.pdf-upload-content {
    position: relative;
}

.pdf-dropzone {
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #f9fafb;
}

.pdf-dropzone:hover {
    border-color: #667eea;
    background: #f0f0ff;
}

.pdf-dropzone.drag-over {
    border-color: #667eea;
    background: #e8e8ff;
    transform: scale(1.01);
}

.pdf-password-section {
    padding: 16px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    margin-top: 12px;
}

.pdf-loading {
    text-align: center;
    padding: 24px;
}

.mode-toggle {
    background: white;
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.mode-toggle label {
    font-size: 14px;
    font-weight: 600;
    color: #4a5568;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mode-switch {
    position: relative;
    width: 56px;
    height: 28px;
    background: #cbd5e0;
    border-radius: 14px;
    cursor: pointer;
    transition: 0.3s;
    flex-shrink: 0;
}

.mode-switch.active {
    background: #667eea;
}

.mode-switch::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.mode-switch.active::after {
    left: 31px;
}

.bulk-upload {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.bulk-upload.active {
    display: block;
}

.card-type-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 8px;
}

.card-type-selector label {
    padding: 12px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    transition: 0.2s;
    font-size: 13px;
    font-weight: 600;
}

.card-type-selector input[type="radio"] {
    display: none;
}

.card-type-selector input[type="radio"]:checked+span {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: block;
    padding: 12px;
    border-radius: 6px;
    margin: -12px;
}

/* Gemini Configuration Panel */
.gemini-config {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #0ea5e9;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.gemini-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.gemini-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #0369a1;
}

.gemini-status {
    font-size: 11px;
    color: #64748b;
    padding: 3px 8px;
    background: white;
    border-radius: 12px;
}

.gemini-settings {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #bae6fd;
}

.gemini-settings input[type="url"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 8px;
    box-sizing: border-box;
}

.gemini-settings input[type="url"]:focus {
    outline: none;
    border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

.privacy-consent {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.privacy-consent input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.privacy-consent small {
    color: #64748b;
    font-size: 11px;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e0;
    transition: 0.3s;
    border-radius: 24px;
}

.switch .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch input:checked+.slider {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.switch input:checked+.slider:before {
    transform: translateX(20px);
}

.bulk-dropzone {
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    background: #f7fafc;
    cursor: pointer;
    transition: 0.3s;
}

.bulk-dropzone:hover {
    border-color: #667eea;
    background: #edf2f7;
    transform: translateY(-2px);
}

.bulk-dropzone.drag-over {
    border-color: #667eea;
    background: #e6f2ff;
    transform: scale(1.02);
}

.loader {
    display: none;
    text-align: center;
    padding: 20px;
    background: #f0f9ff;
    border: 2px solid #3b82f6;
    border-radius: 8px;
    margin-top: 16px;
}

.loader.active {
    display: block;
}

.loader .spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #e0e7ff;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.pairing-results {
    display: none;
    margin-top: 16px;
}

.pairing-results.active {
    display: block;
}

.pair-card {
    background: white;
    border: 2px solid #10b981;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
}

.pair-card.incomplete {
    border-color: #f59e0b;
}

.pair-card-header {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #1f2937;
}

.pair-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.pair-image {
    text-align: center;
}

.pair-image img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid #e5e7eb;
}

.pair-image .label {
    font-size: 11px;
    font-weight: 600;
    margin-top: 6px;
    color: #64748b;
}

.pair-image.front .label {
    color: #10b981;
}

.pair-image.back .label {
    color: #3b82f6;
}

.pair-image.missing {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    border: 2px dashed #f59e0b;
    border-radius: 6px;
    color: #f59e0b;
    font-size: 12px;
}

.main-content {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
}

.empty-state .icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.sheet-container {
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    background: #f7fafc;
}

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.sheet-header input {
    border: none;
    background: transparent;
    font-size: 18px;
    font-weight: 600;
    color: #2d3748;
    padding: 4px 8px;
    border-radius: 4px;
    flex: 1;
    min-width: 150px;
}

.sheet-header input:focus {
    outline: none;
    background: white;
    box-shadow: 0 0 0 2px #667eea;
}

.sheet-actions {
    display: flex;
    gap: 8px;
}

.upload-zones {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.upload-zone {
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    padding: 30px 20px;
    text-align: center;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.upload-zone:hover {
    border-color: #667eea;
    background: #f7fafc;
    transform: translateY(-4px);
}

.upload-zone.has-image {
    border-color: #10b981;
    border-style: solid;
}

.upload-zone.drag-over {
    border-color: #667eea;
    background: #e8e8ff;
    transform: scale(1.02);
}

.editors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.mini-editor {
    background: white;
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    overflow: visible;
}

.mini-editor-label {
    font-size: 12px;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.canvas-wrapper {
    position: relative;
    background: #1a202c;
    border-radius: 6px;
    margin-bottom: 10px;
    overflow: visible;
    padding: 15px;
}

.canvas-container {
    position: relative;
    width: 100%;
    height: 250px;
    overflow: visible;
    cursor: move;
    touch-action: none;
    background: #1a202c;
    border-radius: 6px;
}

.canvas-container.panning {
    cursor: grabbing !important;
}

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

.corner-handle {
    position: absolute;
    width: 24px;
    height: 24px;
    background: #667eea;
    border: 3px solid white;
    border-radius: 50%;
    cursor: crosshair;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    z-index: 100;
    transition: 0.2s;
    touch-action: none;
}

.corner-handle:hover {
    width: 24px;
    height: 24px;
    background: #764ba2;
    cursor: move;
}

.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

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

.zoom-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: #667eea;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    flex-shrink: 0;
}

.zoom-btn:hover {
    background: #764ba2;
    transform: scale(1.1);
}

.zoom-level {
    display: flex;
    align-items: center;
    padding: 0 6px;
    font-size: 10px;
    font-weight: 600;
    color: #4a5568;
    min-width: 40px;
    justify-content: center;
}

.mini-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.mini-controls label {
    font-size: 10px;
    font-weight: 600;
    color: #4a5568;
    margin-right: 4px;
}

.mini-controls input[type="range"] {
    flex: 1;
    height: 4px;
    min-width: 100px;
}

.control-row {
    display: flex;
    gap: 4px;
    align-items: center;
    flex: 1;
    min-width: 140px;
}

.print-preview {
    display: none;
}

.btn {
    padding: 10px 18px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.6);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: #e2e8f0;
    color: #2d3748;
    padding: 8px 14px;
    font-size: 12px;
}

.btn-secondary:hover {
    background: #cbd5e0;
    transform: translateY(-1px);
}

.btn-icon {
    padding: 8px 12px;
}

.footer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 2px solid #e2e8f0;
    gap: 12px;
    flex-wrap: wrap;
}

input[type="file"] {
    display: none;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 8px;
    }

    .header h1 {
        font-size: 24px;
    }

    .header p {
        font-size: 12px;
    }

    .mode-toggle {
        padding: 10px 16px;
        flex-direction: column;
        gap: 12px;
    }

    .mode-toggle label {
        font-size: 12px;
        flex-direction: column;
        text-align: center;
    }

    .bulk-upload {
        padding: 16px;
    }

    .card-type-selector {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .main-content {
        padding: 16px;
    }

    .sheet-container {
        padding: 12px;
    }

    .sheet-header {
        font-size: 16px;
    }

    .sheet-header input {
        font-size: 16px;
    }

    .upload-zones {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .editors-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .mini-editor-label {
        flex-direction: column;
        align-items: flex-start;
    }

    .zoom-controls {
        width: 100%;
        justify-content: space-between;
    }

    .canvas-container {
        height: 200px;
    }

    .footer-actions {
        flex-direction: column;
        gap: 12px;
    }

    .footer-actions>* {
        width: 100%;
    }

    .pair-images {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 20px;
    }

    .bulk-dropzone {
        padding: 30px 15px;
    }

    .canvas-container {
        height: 180px;
    }

    .corner-handle {
        width: 24px;
        height: 24px;
    }

    .zoom-btn {
        width: 32px;
        height: 32px;
    }
}

@media print {
    body {
        background: white !important;
        padding: 0 !important;
    }

    .header,
    .mode-toggle,
    .bulk-upload,
    .pdf-upload-section,
    .sheet-actions,
    .footer-actions,
    .zoom-controls,
    .mini-controls,
    .upload-zones,
    .editors-grid,
    .sheet-header,
    .download-actions {
        display: none !important;
    }

    .container {
        max-width: 100% !important;
    }

    .main-content {
        box-shadow: none !important;
        padding: 0 !important;
        background: white !important;
    }

    .sheet-container {
        page-break-after: always;
        border: none !important;
        background: white !important;
        padding: 10mm !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    .sheet-container:last-child {
        page-break-after: auto;
    }

    .print-preview {
        display: flex !important;
        flex-direction: row !important;
        gap: 5mm;
        align-items: flex-start;
        justify-content: flex-start;
    }

    .print-preview img {
        width: 85.6mm !important;
        height: 54mm !important;
        object-fit: contain;
        display: block;
        border: 1px solid #e5e7eb;
    }

    @page {
        size: A4 portrait;
        margin: 0;
    }
}