/* --- Base --- */
* { box-sizing: border-box; }
body { margin: 0; padding: 0; background: #f1f5f9; font-family: 'Segoe UI', sans-serif; }

/* --- Header --- */
.app-header {
    background: #0f172a; color: white; padding: 15px 20px;
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.btn-main-print {
    background: #2563eb; border: none; color: white; padding: 10px 25px;
    border-radius: 6px; font-weight: 600; cursor: pointer;
}
.btn-main-print:hover { background: #1d4ed8; }

/* --- Layout --- */
.work-area {
    display: flex; flex-wrap: wrap; gap: 20px; padding: 20px;
    max-width: 1400px; margin: 0 auto;
}
.sidebar { flex: 1; min-width: 280px; max-width: 350px; }

/* Upload Box */
.input-wrapper {
    position: relative; border: 2px dashed #94a3b8; border-radius: 12px;
    height: 180px; display: flex; align-items: center; justify-content: center;
    background: white; cursor: pointer; transition: 0.3s;
}
.input-wrapper:hover { border-color: #2563eb; background: #eff6ff; }
#file-input { position: absolute; width: 100%; height: 100%; opacity: 0; cursor: pointer; z-index: 2; }
.upload-ui { text-align: center; color: #64748b; pointer-events: none; }
.upload-ui i { font-size: 40px; margin-bottom: 10px; color: #2563eb; }

.card-list-info { background: white; padding: 20px; border-radius: 12px; margin-top: 20px; }
.btn-reset { width: 100%; background: #ef4444; color: white; padding: 10px; border: none; border-radius: 6px; margin-top: 10px; cursor: pointer; }

/* --- A4 Sheet Preview --- */
.sheet-container {
    flex: 2; display: flex; justify-content: center; background: #cbd5e1;
    padding: 20px; overflow: auto; min-height: 600px; border-radius: 12px;
}
.a4-page {
    width: 210mm; height: 297mm; background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
    padding: 10mm; position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 5mm;
}
.sheet-watermark { position: absolute; top: 40%; width: 100%; text-align: center; color: #cbd5e1; }
.printed-card {
    width: 6.75in; height: 2.25in; border: 1px solid #e2e8f0;
    object-fit: contain; background: white; cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.printed-card:hover { box-shadow: 0 0 0 2px #ef4444; }

/* --- MODAL (NATIVE SCROLL FIX) --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); z-index: 9999;
    display: none; justify-content: center; align-items: center;
    padding: 20px;
}
.modal-box {
    background: white; 
    width: 800px; max-width: 95%;
    height: 90vh; /* Fixed height to force scroll inside */
    border-radius: 12px; display: flex; flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal-header {
    padding: 10px 20px; background: #f8fafc; border-bottom: 1px solid #e2e8f0;
    display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
.header-controls { display: flex; gap: 10px; }
.btn-tool {
    background: white; border: 1px solid #cbd5e1; width: 36px; height: 36px;
    border-radius: 6px; cursor: pointer; color: #334155; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
}
.btn-tool:hover { background: #e2e8f0; color: #2563eb; }
.btn-close { font-size: 28px; border: none; background: none; cursor: pointer; color: #64748b; }

/* SCROLLABLE BODY */
.modal-body {
    flex: 1; /* Fills remaining height */
    overflow: auto; /* Enable Native Scrollbars */
    background: #333; 
    position: relative;
    padding: 0;
}

/* Wrapper for Cropper to allow expansion */
.cropper-wrapper-div {
    width: 100%;
    min-height: 100%;
}

#image-to-crop { max-width: 100%; display: block; }

.modal-footer {
    padding: 15px 20px; background: white; border-top: 1px solid #e2e8f0;
    display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
.btn-confirm {
    background: #2563eb; color: white; padding: 12px 25px; border: none;
    border-radius: 6px; font-weight: 600; cursor: pointer;
}
.btn-cancel {
    background: #94a3b8; color: white; padding: 12px 20px; border: none;
    border-radius: 6px; cursor: pointer; margin-right: 10px;
}

/* --- PRINT RULES --- */
@media print {
    body * { visibility: hidden; }
    #printable-a4, #printable-a4 * { visibility: visible; }
    #printable-a4 {
        position: absolute; left: 0; top: 0; width: 100%; margin: 0;
        padding: 5mm; box-shadow: none; background: white;
    }
    .printed-card { border: none; margin: 0 auto 5mm auto; display: block; }
    .sheet-watermark { display: none; }
    @page { size: A4; margin: 0; }
}